S
Sam Gentle
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 =3D 1.0/0.0
=3D> Infinity
irb(main):002:0> 1..inf
=3D> 1..Infinity
Hoorah! But not just that.
irb(main):003:0> 'a'..inf
=3D> "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' <=3D> 3
=3D> false
irb(main):005:0> 3 <=3D> 'a'
=3D> nil
And hence:
irb(main):006:0> 'a'..3
=3D> "a"..3
irb(main):007:0> 3..'a'
ArgumentError: bad value for range
from (irb):7
Zounds,
Sam
viable way to cram unbounded lists into the Range implementation when
I stumbled on this...
irb(main):001:0> inf =3D 1.0/0.0
=3D> Infinity
irb(main):002:0> 1..inf
=3D> 1..Infinity
Hoorah! But not just that.
irb(main):003:0> 'a'..inf
=3D> "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' <=3D> 3
=3D> false
irb(main):005:0> 3 <=3D> 'a'
=3D> nil
And hence:
irb(main):006:0> 'a'..3
=3D> "a"..3
irb(main):007:0> 3..'a'
ArgumentError: bad value for range
from (irb):7
Zounds,
Sam