From: "Matthew K. Williams" Date: 2009-07-17T02:31:10+09:00 Subject: Re: case statement puzzle - correction --8323329-485689195-1247765486=:23524 Content-Type: MULTIPART/MIXED; BOUNDARY="8323329-485689195-1247765486=:23524" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-485689195-1247765486=:23524 Content-Type: TEXT/PLAIN; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE On Fri, 17 Jul 2009, F. Senault wrote: > Le 16 juillet 2009 =E0 18:58, Tom Cloyd a =E9crit : > >> x=3D'1' >> case >> when x =3D=3D'0' >> puts '0' >> when (1..5).include? x.to_i >> puts '1' >> end > > When in doubt, parenthesise : > >>> case > ?> when x =3D=3D '0' >>> puts '0' >>> when (1..5).include?(x.to_i) >>> puts '1' >>> end > 1 > =3D> nil > Seconded. You could also have said: when ((1..5).include? x.to_i) In ruby, parenthesis are optional.... except when they aren't. ;-) Matt --8323329-485689195-1247765486=:23524-- --8323329-485689195-1247765486=:23524--