From: Mikael Brockman Date: 2004-10-11T07:31:00+09:00 Subject: Re: Putting some code out to DRY Mauricio Fern�ndez writes: > On Mon, Oct 11, 2004 at 04:25:30AM +0900, trans. (T. Onoma) wrote: > > > > Notice the three lines of duplication. Any ideas on DRYing this up? > > > > def each > > seed = @start > > Am I the only one who sometimes does things resembling > whatever = lambda do > yield(seed) > @skip.times { seed = seed.succ } > break if @halt.call(seed) if @halt > end > and then whatever[] ?? Nope. I do that all the time. I also often do stuff like class Foo define_thing = lambda do |id, y| define_method x do |z| do_some_stuff z, y do_some_other_stuff z, y end end define_thing.call :foo define_thing.call :bar define_thing.call :baz end