From: Josh Cheek Date: 2010-02-15T15:35:44+09:00 Subject: Re: 'def', but with a closure --000e0cd13be093d24c047f9dd3ec Content-Type: text/plain; charset=ISO-8859-1 Is there some reason why Ruby hasn't made it possible to just do @cars.each do |owner, model| widget = TkLabel.new( :text => model ) widget.define_method( :get_owner ) { owner } end I find myself conceptually knowing what I want to do, but having to jump through lots of hoops to do it, or telling myself that I'm not supposed to do eval <<-END_OF_METHOD def widget.get_owner #{owner.inspect} end END_OF_METHOD But if I'm supposed to avoid things like that, then why make them so much easier than the alternative? Eval worked first time I tried (granted my test case had owner as a string), but I spent maybe 30 min trying to get Albert's way to work. Hidetoshi's solution works because of TkLabel's behaviour, but can't be expected to work for any object (ie not generalizable). Is it supposed to be an act of discouragement, to prevent us from doing something dangerous? Was it just not considered that most people would want or need to do something like this? Is it something that is actually very difficult to implement / not possible, due to a deeper Ruby model than I understand? Is it actually really easy, and I just am slow to catch on? Any thoughts? Capability like this gets me excited, but the difficulty of implementing it makes me frustrated. --000e0cd13be093d24c047f9dd3ec--