Re:Implementing Set#to_proc and Hash#to_proc in Ruby
by steventhedev on Friday November 28, 2014 @01:30PM
(#8671722)
FYI - the ampersand syntax is only in function calls, so the following will fail:
Whereas this will not:
Generally speaking, & is syntactic sugar for .to_proc, but only within function calls.
[ Parent
| on HN ]
Re:Implementing Set#to_proc and Hash#to_proc in Ruby
by byroot on Friday November 28, 2014 @01:57PM
(#8671798)
> & is syntactic sugar for .to_proc, but only within function calls
It's not exactly that. & is the syntax to pass a variable as a block to a method. And ruby will implicitly call to_proc on the object it receive as a block.
I know it seems pedantic, but there is a difference.