Skip to content

Instantly share code, notes, and snippets.

@mykiy
Last active April 3, 2018 11:36
Show Gist options
  • Save mykiy/b008ba99831273be71575c480fd0b104 to your computer and use it in GitHub Desktop.
Save mykiy/b008ba99831273be71575c480fd0b104 to your computer and use it in GitHub Desktop.
lambda in ruby
l = -> (name) { puts "#{name}" }
l.call("velu")
=>
velu
--------
l = -> (num) { num * 5 } # l is the variable which stores the block of code, when we calls the l the block of code will be executed.
l.call(5) #Another important thing is lambda is an object.
=>
25
-----
multiple lambdas
l = -> (a,b) { a + b }
l.call(1,2)
=> 3
------
l = lambda do # do..end block in lambda
puts "hello"
end
l.call
--------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment