|
|
|
|
|
by lcnPylGDnU4H9OF
1094 days ago
|
|
> &:operation If one is unfamiliar, this syntax will implicitly call `Symbol#to_proc` on `:operation` and pass that as a block to the method (it will work with any object which responds to `#to_proc` and returns an object which responds to `#call`). These lines are all equivalent: my_array.map(&:operation)
my_array.map { |my_element| my_element.operation }
my_array.map { |my_element| :operation.to_proc.call(my_element) }
Given that, I adore the terseness in the first line, though I can understand a certain annoyance that the shorthand can cause if one doesn't know how this works. |
|