From: Joel VanderWerf Date: 2008-05-02T04:43:51+09:00 Subject: Re: Noob Q: ruby block scoping question (ruby TK) Albert Schlef wrote: > Joel VanderWerf wrote: >> @btn = TkButton.new(btn_frame).then { |w| >> w.text "My Button" # w must be referred to explicitly >> w.background get_color # calls method in expected scope >> w.state 'normal' >> w.command proc { >> @btn.configure 'state'=>'disabled' >> # @btn has expected scope >> } >> w.pack('side'=>'left', 'padx'=>10, 'pady'=>10) >> } > > Is it possible to do 'w.configure ...' instead of '@btn.configure ...'? > Why did you choose the latter? Sorry, bad example. Thanks for pointing that out. It should really be w. I was trying to show that you can refer to instance variables of the same instance as in the outer scope. So, for example, if you had another button that was disabled by pressing this one, you might express that as: @btn2 = ... @btn1 = TkButton.new(btn_frame).then { |w| w.command proc { @btn2.configure 'state'=>'disabled' } } -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407