From: harryo@... (Harry Ohlsen) Date: 2002-05-02T23:51:38+09:00 Subject: A scoping issue I'm trying to write a class that constructs a Tk dialog and am hitting an issue to do with the scope of instance variables. As part of the processing, what I want is something similar to the following code (I've made it non-Tk, to show up the essence of the problem) ... class A def initialize(&block) @code = block end end class B def initialize @x = 123 a = A.new(proc { puts @x }) a.execute end end The problem is that, of course, the reference to @x assumes it's an instance variable of class A, rather than the one from class B, in the outer scope. Is there some way I can get the block passed to the A.new to end up with the @x from the instance of B that I'm constructing? Please note that I didn't write the equivalent of class A (it's a Tk provided one), so I can't cleanly add an extra variable to its initialize(). Currently, I'm setting a global variable, but I really dislike that, even though it works OK in this case, because there'll only ever be one instance of B in existence at a time. Is there a clean way I can do this?