Ruby 1.9 brings a shorter way to define lambdas using the ->
operator:
twice = -> (x) { 2 * x }
twice.call(5) # => 10
This is equivalent to:
twice = 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 }
.
Posted by Henning Koch to makandra dev (2013-07-17 06:49)