From: "tobyclemson@..." Date: 2007-07-04T20:04:56+09:00 Subject: Re: Ruby case statement Thanks, that's neater than the ways of doing it that I have found since first posting. On Jul 4, 11:36 am, Sharon Phillips wrote: > > case type > > when 1 > > # do stuff for type 1 > > when 1,2 > > # do stuff for both type 1 and 2 > > end > > > If it isn't valid, what is the easiest way to obtain this > > functionality > > i=1 > case i > when 1: puts "1" > when 1,2: puts "1 or 2" > when 3: puts "3" > else puts "other" > end > > > 1 > > so it looks like the second one gets skipped. > > The best i can come up with (but I'm pretty sure someone else will > come up with a much better alternative) is > > i=1 > case i > when 1,2 > puts "1 or 2" > puts "1" if i==1 > when 3 > puts "3" > else > puts "other" > end > > > 1 or 2 > > 1 > > Cheers, > Dave