From: "David A. Black" Date: 2005-11-26T09:23:44+09:00 Subject: Re: Fun with ranges! Hi -- On Sat, 26 Nov 2005, Sam Gentle wrote: > So I was messing around today trying to find out whether there was a > viable way to cram unbounded lists into the Range implementation when > I stumbled on this... > > irb(main):001:0> inf = 1.0/0.0 > => Infinity > > irb(main):002:0> 1..inf > => 1..Infinity > > Hoorah! But not just that. > > irb(main):003:0> 'a'..inf > => "a"..Infinity > > Hold on a second, I said to myself, that doesn't make any sense... inf > is a Float and "a" is a string! That's when I discovered ruby's > dastardly secret: > > irb(main):004:0> 'a' <=> 3 > => false > irb(main):005:0> 3 <=> 'a' > => nil > > And hence: > > irb(main):006:0> 'a'..3 > => "a"..3 > irb(main):007:0> 3..'a' > ArgumentError: bad value for range > from (irb):7 What version of Ruby are you using? $ ruby -ve '"a"..3' ruby 1.8.3 (2005-09-21) [powerpc-darwin8.3.0] -e:1: warning: useless use of .. in void context -e:1: bad value for range (ArgumentError) David -- David A. Black dblack@wobblini.net