From: Michael Neumann Date: 2001-11-30T07:46:25+09:00 Subject: [ruby-talk:26988] Re: short article draft for review Tobias Reif wrote: > Dave Thomas wrote: > > > Michael Neumann writes: > > > >>You could here also use Symbols (:even) instead of Strings. > >> > > And perhaps a case statement > > > Thank you both! > ... like that? anything else? > > -----8<----- > def upto limit,modifier=:default > case modifier > when :even > number = 2 > step = 2 > when :odd > number = 1 > step = 2 > when :default > number = 1 > step = 1 > end > while number <= limit > yield number > number += step > end > end Instead of assigning number and step in each when-clause, why not use this (case is an expression!): number, step = case modifier when :even then [2,2] when :odd then [1,2] when :default then [1,2] end Or reformat it appropriately (this is the only problem I have with this, correct formatting). Regards, Michael -- Michael Neumann merlin.zwo InfoDesign GmbH http://www.merlin-zwo.de