http://www.ruby-doc.org/core/classes/Kernel.html#M001057
http://www.ruby-doc.org/core/classes/Binding.html
http://onestepback.org/index.cgi/Tech/Ruby/RubyBindings.rdoc/style/print
def getBinding(str)
return binding
end
str = "hello"
eval "str + ' Fred'" #=> "hello Fred"
eval "str + ' Fred'", getBinding("bye") #=> "bye Fred"
class Demo
def initialize(n)
@secret = n
end
def getBinding
return binding()
end
end
k1 = Demo.new(99)
b1 = k1.getBinding
k2 = Demo.new(-3)
b2 = k2.getBinding
p eval("@secret", b1) #=> 99
p eval("@secret", b2) #=> -3
p eval("@secret") #=> nil
def getBinding(param)
return binding()
end
b = getBinding("hello")
p eval("param", b) #=> "hello"
沒有留言:
張貼留言