Optimizing breadth-first-search code
I'm not sure if I understand your input data correctly, since I don't get this $queue.pop(start.to_i), but:


I won't mention codestyle issues -- I'll talk about algorithm.
Looks like your search is really Depth-first, since it doesn't find the shortest path:

$h = {?0=&gt;[?1,?2,?3], ?1=&gt;[?3], ?3=&gt;[?4]}
p find_path ?0,?4
=&gt; ["0", "1", "3", "4"]


it is because:


it calls recursion immediately before iterating the rest of child nodes
in real Breadth-first you have to store a lot of paths at the same time

Use Set instead of Array for visited, since it looks up immediately instead of searching the value from the beginning of the list.
The easiest way to implement both of these searches with no risk of stack overflow is to use stack of the next states, that we should analyze instead of recursion. Also in this way we don't need global variables or other namespace tricks, since we just do the loop, where path is used instead of $queue and returnArray:


Take this code:

def find_path start, endpoint
  require "set"
  visited = Set.new
  stack = [[start.to_s]]
  until stack.empty?
    path = stack.shift
    start = path.last
    get_next_paths(start).each do |i|
      return path.push i if i == endpoint.to_s
      next if visited.include? i
      visited &lt;&lt; start
      stack.push path+[i]
    end
  end
end


And run this:

$h = {?0=&gt;[?3,?2,?1], ?1=&gt;[?5], ?3=&gt;[?4], ?5=&gt;[?4], ?2=&gt;[], ?4=&gt;[]}
p find_path_ ?0,?4


The fun thing is how it is now easy to switch between Depth and Breadth by just replacing .shift with .pop:

["0", "3", "4"]
["0", "1", "5", "4"]