From: Rob Burrowes Date: 2006-05-04T07:49:15+09:00 Subject: Newbee Question on what if x === 2..5 does --Apple-Mail-236-885624343 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed I'm new to ruby and don't understand why the following code does what is does. Can anyone enlighten me? ruby -e 'a = [1,2,3,4,5,6,7,8,9,10]; a.each { |x| if (x === 2..5 ) then print x, " " end}; puts ' 2 3 4 5 6 7 8 9 10 I would have thought this would be the same as ruby -e 'a = [1,2,3,4,5,6,7,8,9,10]; a.each { |x| case x; when 2..5 then print x, " "; end}; puts ' 2 3 4 5 I am also confused that ruby -e 'while gets; print if /
/; end' < fred
UETHUEPUK THEUTEUH teuhepxn thueonhoe ononueuouh
and a three . range test give the same output. ruby -e 'while gets; print if /
/; end' < fred
UETHUEPUK THEUTEUH teuhepxn thueonhoe ononueuouh
The original file 'fred' is hello
UETHUEPUK THEUTEUH teuhepxn thueonhoe ononueuouh
ruby -v ruby 1.8.4 (2005-12-24) [powerpc-darwin8.6.0] Compiled from the distribution, not the Mac OS shipped version. Rob Rob Burrowes Ph: +64 (9) 3737 599 Extn 87972 Computing Services Manager Fax: +64 (9) 3737 453 Computer Science Department Mob:+64 (27) 4731 856 The University of Auckland Rm 391, Level 3 38 Princes Street http://www.cs.auckland.ac.nz/~rob Private bag 92019 http://www.wikarekare.org Auckland 1001 http://www.burrowes.org --Apple-Mail-236-885624343--