From: "Mauricio Fernández" Date: 2004-12-03T18:00:23+09:00 Subject: Re: nested defs, what if... On Fri, Dec 03, 2004 at 03:02:49PM +0900, trans. (T. Onoma) wrote: > Yes, I think so since lambdas are not singleton/multiton (could they be?) Of > course the fix is something like: > > class A > def a(y) > @a_b ||= lambda { |x| x + y } > 10.times { |i| print @a_b(i) } > end > end Not quite... >> class A; def a(y); @a_b ||= lambda { |x| x + y }; 10.times { |i| >> print @a_b[i]}; end end => nil >> a = A.new => # >> a.a(10) 10111213141516171819=> 10 >> a.a(1000) 10111213141516171819=> 10 > But true inner methods would be the bomb for these use cases (IMHO). They don't seem any more powerful than lambdas, just sugar. They would offer some opportunities for optimization though. -- Hassle-free packages for Ruby? RPA is available from http://www.rubyarchive.org/