Ruby binding usage example
class Demo
def initialize(n)
@secret = n
end
def get_binding
return binding()
end
end
d1 = Demo.new(3)
d2 = Demo.new(4)
a1 = d1.get_binding
a2 = d2.get_binding
puts eval("self", a1)
puts eval("@secret", a2)
def get_binding(param)
return binding
end
b = get_binding("hello")
puts eval("param", b)
No comments :
Post a Comment