Created
May 16, 2015 12:45
-
-
Save KamilLelonek/80daccb842ea45110794 to your computer and use it in GitHub Desktop.
Closures example 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
[1] (pry) main: 0> outer = 1 | |
=> 1 | |
[2] (pry) main: 0> increment = -> value { outer + value } | |
=> #<Proc:0x007fb94c87e148@(pry):2 (lambda)> | |
[3] (pry) main: 0> increment[2] | |
=> 3 | |
[4] (pry) main: 0> increment::(2) | |
=> 3 | |
[5] (pry) main: 0> increment.(2) | |
=> 3 | |
[6] (pry) main: 0> increment.call(2) | |
=> 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment