Created
October 31, 2012 13:17
-
-
Save taiki45/3986983 to your computer and use it in GitHub Desktop.
after reading RHG
This file contains 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
def closure(x = 3) | |
Proc.new { x } | |
end | |
a = closure | |
a.call #=> 3 | |
a.binding.eval "x" #=> 3 | |
b = closure 5 | |
eval "x", b.binding #=> 5 | |
env = closure {|z| z + 3 }.binding | |
eval "yield x", env #=> 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment