Skip to content

Instantly share code, notes, and snippets.

@k2works
Created December 22, 2014 06:17
Show Gist options
  • Save k2works/dbbe26f8d5e317e09cb5 to your computer and use it in GitHub Desktop.
Save k2works/dbbe26f8d5e317e09cb5 to your computer and use it in GitHub Desktop.
evalにBindingオブジェクトを使った場合
class EvalTarget
def initialize
@instance_val = 'instance valiable'
end
def instance_binding
local_val = 'local valiable' # !> assigned but unused variable - local_val
binding
end
private
def private_method
'private method'
end
end
e1 = EvalTarget.new
binding_obj = e1.instance_binding
eval "@instance_val", binding_obj
eval "local_val", binding_obj
eval "private_method", binding_obj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment