Tech Tip: Easily Create a Lambda in Ruby

ruby

 

For those of you who are Ruby on Rails developers, Lambdas are a newly introduced concept for defining scopes, a Lambda Literal, identified with the sign ->  , allows you to easily create a Lambda. See the example below:

 

 

a = -> { 1 + 1 }

a.call

# => 2

a = -> (v) { v + 1 }

a.call(2)

# => 3

Advertisements

Leave a Reply