From: Tom Cloyd Date: 2009-07-17T02:12:27+09:00 Subject: Re: case statement puzzle James Coglan wrote: > 2009/7/16 Tom Cloyd > > >> I'm missing something here, and cannot see the problem: >> >> x='1' >> (1..5).include? x.to_i # => true >> >> But... >> >> 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 > > The basic idea is that anything following 'when' should respond to '===' to > indicate membership, or type/pattern-matching. e.g. Module#=== tells you > whether the argument is an instance of the receiving module, Regexp#=== > tests a regex against a string. > > -- > James Coglan > http://jcoglan.com > > THANKS! That's the "missing piece" - I need to study up on "===", about which I know nothing. 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) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~