Skip to content

Instantly share code, notes, and snippets.

@taiki45
Created October 31, 2012 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taiki45/3986983 to your computer and use it in GitHub Desktop.
Save taiki45/3986983 to your computer and use it in GitHub Desktop.
after reading RHG
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