Bindings : eval « Reflection « Ruby






Bindings


def binding_elsewhere
  x = 20
  return binding
end

remote_binding = binding_elsewhere

x = 10
eval("puts x")
eval("puts x", remote_binding)
eval("x = 10")
eval("x = 50", remote_binding)
eval("puts x")
eval("puts x", remote_binding)

 








Related examples in the same category

1.Dynamic Code Execution
2.uses strings and interpolation with Dynamic Code Execution