Ruby — MRI 2.0.0, pasted 4 years ago (json)
1 2 3 4 5 6 7 8 9 10 11 | require 'ostruct'
not_in_locals = "we don't want this"
locals = {a: 1, b: 2}
class Vars < OpenStruct
def get_binding() binding; end
end
vars = Vars.new(locals).get_binding
p vars.eval "a" # good, we want this
p vars.eval "b" # good, we want this
p vars.eval "not_in_locals" # bad, it shouldn't know this
|
1 2 nil
OK (0.036 sec real, 0.035 sec wall, 8 MB, 74 syscalls)