dijkstra algorithm solved in ruby