From: Brian Candler Date: 2010-10-21T17:58:47+09:00 Subject: Re: scope when reopening method Rahul Kumar wrote in post #956019: > The second option of "when needed" wont work since My will call meth() > at > some point that i don't know. I would have liked to leave meth() blank > so that callers can do what they want there. Yes, so my suggested solution would be to pass arr at the time the object is instantiated: arr = [] m = My.new(arr) # <<< NOTE def m.meth(str) # access some other object in application scope @arr << str do_something str # call some method in my app end i.e. you squirrel it away in an instance variable for later use. > However, i had sort of hoped somehow the reopened method could access > scope of the class that was reopening it. You have clearly explained > that it is operating in the space of the class itself. So no magic can > happen here :( Well, the particular example you showed *can* be made to work, using define_method() instead of def. That doesn't open a new scope, and so you have a closure, i.e. access to all the local variables in the enclosing scope. arr = [] m = My.new class <