2 ms·
FYI - the ampersand syntax is only in function calls, so the following will fail: &set.call(1) Whereas this will not: (1..30).select(&set) Generally
by steventhedev 12y ago
FYI - the ampersand syntax is only in function calls, so the following will fail:
&set.call(1)
Whereas this will not:
(1..30).select(&set)
Generally speaking, & is syntactic sugar for .to_proc, but only within function calls.
- byroot 12y ago> & 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.