From: Gavin Sinclair Date: 2004-12-03T14:00:44+09:00 Subject: Re: nested defs, what if... On Friday, December 3, 2004, 1:47:32 PM, nobu wrote: > Hi, > At Fri, 3 Dec 2004 08:20:34 +0900, > trans. (T. Onoma) wrote in [ruby-talk:122265]: >> Well, it's an idea, but I don't think a very good one. In general I don't >> think this is useful, and would rather obfuscate code if actually used. I >> think what would be more useful is if such methods were local methods, like >> local variables: > I also have thought the idea, though haven't implemented it. > I'm still worndering whether this should be valid or error. > class A > def a(y) > def b(x) > x + y # `y' in a or `undefined local variable'? > end > 10.times{ |i| print b(i) } > end > end Is there any difference between an "inner method" (with 'y' in a) and a lambda? I've happily used lambdas to define private functionality before, but I'm concerned about efficiency: class A def a(y) b = lambda { |x| x + y } 10.times { |i| print b(i) } end end Does the lambda attached to b get regenerated with each call to a? Gavin