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 /<div id=.*$/ … /</body>/; end’ < fred
and a three . range test give the same output.
ruby -e ‘while gets; print if /<div id=.*$/ … /</body>/; end’ < fred
The original file ‘fred’ is
helloruby -v
ruby 1.8.4 (2005-12-24) [powerpc-darwin8.6.0]
Compiled from the distribution, not the Mac OS shipped version.
Rob
Rob B. 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 Robs Home Page
Private bag 92019 http://www.wikarekare.org
Auckland 1001 http://www.burrowes.org