Last active
April 3, 2018 11:36
-
-
Save mykiy/b008ba99831273be71575c480fd0b104 to your computer and use it in GitHub Desktop.
lambda in ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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