From: Tom Cloyd Date: 2009-07-17T07:01:07+09:00 Subject: Re: case statement puzzle Bertram Scharpf wrote: > Hi, > > Am Freitag, 17. Jul 2009, 02:12:27 +0900 schrieb Tom Cloyd: > >> James Coglan wrote: >> >>> 2009/7/16 Tom Cloyd >>> >>>> x='1' >>>> case >>>> when x =='0' >>>> puts '0' >>>> when (1..5).include? x.to_i >>>> puts '1' >>>> end >>>> >>> What about: >>> >>> x='1' >>> case >>> when x =='0' >>> puts '0' >>> when '1'..'5' >>> puts '1' >>> end >>> >>> >> THANKS! That's the "missing piece" - I need to study up on "===", about >> which I know nothing. >> > > This will output "1" because the Range object '1'..'5' is not nil > and not false. It has nothing to do with the === operator. You > could also write > > x='1' > case > when x == '0' > puts '0' > when "hi, there" > puts '1' > end > > To apply the === operator you have to mention the variable > after the "case" keyword. > > x = '1' > case x > when '0' then puts '0' > when '1'..'5' then puts '1' > end > > Bertram > > > Thanks...you're right, of course, and I soon learned that, in this morning ruby exercise session. Very interesting! t. -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist Bellingham, Washington, U.S.A: (360) 920-1226 << tc@tomcloyd.com >> (email) << TomCloyd.com >> (website) << sleightmind.wordpress.com >> (mental health weblog) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~