From: James Coglan Date: 2009-07-17T01:55:46+09:00 Subject: Re: case statement puzzle --001636c5b680d79f66046ed58a6a Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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 --001636c5b680d79f66046ed58a6a--