From: Rahul Kumar Date: 2010-10-21T17:43:32+09:00 Subject: Re: scope when reopening method Brian Candler wrote in post #956015: > The simple answer(*) is that you can't - each 'def' method and 'class' > definition starts its own local variable scope. That's why they're > called "local" variables :-) > > > Or you could just pass the object reference only when needed: > > def meth(str, arr) > arr << str > do_something str > end > > It depends on the cleanest way to encapsulate the logic you're > implementing. Thanks. I understand that one way is to pass a reference to an object to My. 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. Another approach I had is to pass a block in advance which is stored, meth calls that block. 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 :( -- Posted via http://www.ruby-forum.com/.