First, here’s a piece of working code that prints the values “1 2 3” as one would expect:
class Array
def each2
each {|value| puts value}
end
end
[1, 2, 3].each2
HOW IN THE NAME OF ALAN TURING DOES each2 PASS value TO each*?!?!
···
It doesn’t. each2 is passing {|value| puts value} to each. The declaration of each is like:
def each(&block)
…iteration block…
block.call(item)
…end iteration…
end
Values are passed to blocks with either “yield item” or “block.call(item)”.
-a