Skip to content

Instantly share code, notes, and snippets.

@jballanc
Created January 15, 2013 23:08
Show Gist options
  • Save jballanc/4543026 to your computer and use it in GitHub Desktop.
Save jballanc/4543026 to your computer and use it in GitHub Desktop.
Implications of MRI's current implementation of bindings...
def munger(&block)
block.binding.eval('b = rand(99)')
end
def doit
a = 1
b = 2
munger do; end
puts "a + b = #{a + b}"
end
doit
@jballanc
Copy link
Author

Should you be able to extract an environment from any closure?

  • Yes
  • No

Should all bindings in the lexical scope of the closure be captured by the environment?

  • All
  • Only those used
  • Only those explicitly specified

Should bindings be live in the environment?

  • All bindings are live and mutable
  • Bindings are live, but read-only
  • Bindings are a snapshot in time
  • User specifies state of each binding

What happens if you define a new binding using the environment?

  • New binding shadows old binding
  • Environment is cloned containing new binding
  • Defining new bindings is not allowed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment