How do I extract all members (methods, variables, constants, objects, etc) of an arbitrary object and pass them to a block?
def 开发者_StackOverflow中文版inside(obj)
#pass all the members of the object to the block
end
inside myLink do
url = "myurl.com"
end
You can use instance_eval:
def inside obj, &block
obj.instance_eval &block
end
You'll still need to use self though:
inside myLink do
self.url = "myurl.com"
# or:
@url = "myurl.com"
end
精彩评论