Is there a shorthand for {|x| foo x}?
You can reference the method to pass as a proc with method
:
list.map(&method(:foo))
Maybe not the shortcut you're looking for, as it's limited to work with methods that expect only one argument and reduces readability.
Adding a bit more context to the answer supplied by Sebastian Palma.
method(:foo)
Returns the method foo
of the current instance (self
). You can also use this in combination with other instances:
(1..10).map(&5.method(:+))
#=> [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
Here 5.method(:+)
returns the +
method for the instance 5
.