From: Jamis Buck Date: 2004-10-11T07:14:22+09:00 Subject: Re: Putting some code out to DRY Mauricio Fern�ndez wrote: > 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[] ?? Glad you mentioned this, batsman. I was just about to. Let me fill in the blank at the end of your example, though, since I'm the type of guy that just can't stand a song only partially sung... @step ? @step.times(&whatever) : loop(&whatever) - Jamis > > > >> if @step >> @step.times do >> yield(seed) >> @skip.times { seed = seed.succ } >> break if @halt.call(seed) if @halt >> end >> else >> loop do >> yield(seed) >> @skip.times { seed = seed.succ } >> break if @halt.call(seed) if @halt >> end >> end >> end >> >>Thanks, >>T. >> >> >>[CO2D] or [WET] ? >> >> > > -- Jamis Buck jgb3@email.byu.edu http://www.jamisbuck.org/jamis