From: Brian Candler Date: 2007-05-09T01:52:14+09:00 Subject: Re: Difference answers from Terminal, TextMate, and BBEdit On Tue, May 08, 2007 at 11:47:28PM +0900, Morton Goldberg wrote: > >On Tue, May 08, 2007 at 07:22:39PM +0900, Morton Goldberg wrote: > >>A case statement like > >> > >> > >>case > >>when 'year' : tree.ageOneYear # , y as shortcut? > >>when (1..100) : tree.pick_an_orange > >>else puts('Don\'t be greedy, don\'t try to pick more than 100 > >>oranges') > >>end > >> > >> > >>just looks for the first true when-clause. In this case that will > >>always be 'year' because everything but false and nil is true in > >>Ruby. > > > >That's incorrect. Case doesn't check if 'year' is true; it checks > >whether > >'year' === obj is true. > > > >Try this: > > > >foo = "Hello" > >case foo > >when "year" > > puts "xxx" > >when /ell/ > > puts "yyy" # this line is run > >end > > Beg to differ with you. This is a case with no argument. It doesn't > have any obj to do a 'year' === obj on. Ugh, you're right. It doesn't even compare against $_. That seems rather pointless, as it's just the same as if .. elsif .. end And what about case when (1..100) # whatever end That would be the flipflop operator borrowed from Perl? But with both ends true as well?