From: Ross Shaw Date: 2002-12-09T19:29:26+09:00 Subject: Re: elseif? In article , Ross Shaw wrote: > In article > , > dblack@candle.superlink.net wrote: > > > Hi -- > > > > On Sun, 8 Dec 2002 nobu.nokada@softhome.net wrote: > > > > > Hi, > > > > > > At Sun, 8 Dec 2002 06:18:52 +0900, > > > Joel VanderWerf wrote: > > > > x = 1.5 > > > > > > > case > > > > when x < 0; puts "x < 0" > > > > when 0 <= x && x < 1; puts "x in interval [0,1)" > > > > when 1 <= x && x < 2; puts "x in interval [1,2)" > > > > when 2 <= x; puts "x >= 2" > > > > end > > > > > > If no expression after "case", "when" clause evaled as true > > > will be executed. > > > > Yet more proof of my theory, which is that as you work on a problem in > > Ruby, and it gets better and more idiomatic, code disappears from the > > screen. > > > > > Oops, I think some more code just disappeared from my screen!!! > > case > when x < 0; puts "x < 0" > when x < 1; puts "x in interval [0,1)" > when x < 2; puts "x in interval [1,2)" > else puts "x >= 2" > end > And using David's suggestion in another post and adding a a twist we lose even more!!! puts "x " + case when x < 0; "< 0" when x < 1; "in interval [0,1)" when x < 2; "in interval [1,2)" else ">= 2" end Although I kind of think I might have gone a little too far and lost some readability in my quest to eliminate duplication. Fore!!!! Ross