From: nobu.nokada@... Date: 2004-12-03T14:18:38+09:00 Subject: Re: nested defs, what if... Hi, At Fri, 3 Dec 2004 14:00:44 +0900, Gavin Sinclair wrote in [ruby-talk:122305]: > > 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? Actually, no. Just a syntax sugar, and it would be implemented using a lambda. And another question; should b be visible from other methods called from a? > 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? I guess so. -- Nobu Nakada