I found this sample code that realizes custom Symbol#to_proc in Ruby:
class Symbol
def to_proc
puts "In the new Symbol#to_proc!"
Proc.new { |obj| obj.send(self) }
end
end
It includes additional "puts ..." string to ensure it is not built-in method. When I execute code
p %w{ david black }.map(&:capitalize)
the result is:
In the new Symbol#to_proc!
["David", "Black"]
But why it is not something like this?
In the new Symbol#to_proc!
["David"]
In the new Symbol#to_proc!
["Black"]
My logic is like this: map yields elements one by one to block. Block takes first element and executes .to_proc, than second. But why puts executes once only?