I was looking that in Ruby there are a lot of ways to declare arrays objects like:
[1,2,3]
Array.new(3){|i| i+1}
Even with more trickier ways like:
Array.new(3, &1.method(:+))
Where the &1.method(:+)
means that the object 1 (reference by value) is responding to the method + directly referenced, so every time (3 times in this case) the array is executing the block, the object increments by 1. I would appreciate any correction if I'm wrong on my analysis here.
So, passing that, there is this case that I'm not completely following:
Array.new(3, &:next)
The question is:
What's the &
doing in this case? I can guess that is a reference to some value directly but I don't know which one exactly. And after the &
, how the :next
is acting in this case.
Beforehand, I really appreciate your help. I'm getting the grasp of Ruby and I'm liking it even more!