the << operator is what confuses me the most
if prev.include? current
p = reconstruct_path(prev, prev[current])
[p] << current
else
current
end
end ```
CodePudding user response:
<< is known as the "shovel". It pushes "things" into other "things". Like this for example:
thing_array = [1,2,3,4,5]
thing_array << 6
Result: => [1, 2, 3, 4, 5, 6]
So the array thing_array
was created with the numbers 1-5. By using the shovel I pushed the new entry into the array. It's just a shortcut to make code cleaner and lighter.
I hope that makes sense.