Posted almost 5 years ago. Visible to the public.
Short lambda syntax in Ruby 1.9
Ruby 1.9 brings a shorter way to define lambdas using the ->
operator:
Copytwice = -> (x) { 2 * x } twice.call(5) # => 10
This is equivalent to:
Copytwice = lambda {|x| 2 * x } twice.call(5) # => 10
Note that the syntax is subtly different from Coffeescript where you define function parameters before the arrow: (x) -> { 2 * x }
.