Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'ostruct'
- not_in_locals = "we don't want this"
- locals = {a: 1, b: 2}
- my_binding = OpenStruct.new(locals).instance_eval { binding }
- p my_binding
- p eval("a", my_binding) #good, we want this
- p eval("b", my_binding) #good, we want this
- p eval("not_in_locals", my_binding) #bad, don't want it to access this, but it can
- ruby binding_of_hash.rb
- foo = foo value
- baz = 42
- binding_of_hash.rb:10:in `eval': undefined local variable or method `not_in_hash' for #<HashBinding:0x007fcc0b9ec1e8> (NameError)
- from binding_of_hash.rb:10:in `eval'
- from binding_of_hash.rb:10:in `evaluate'
- from binding_of_hash.rb:20:in `<main>'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement