# Fun with ranges!

**URL:** <https://www.ruby-forum.com/t/fun-with-ranges/48871>\
**Category:** Ruby\
**Created:** [November 26, 2005, 12:51am UTC](https://www.ruby-forum.com/t/fun-with-ranges/48871 "2005-11-26T00:51:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sgentle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85f322/32.png) [@sgentle](https://www.ruby-forum.com/u/sgentle)\
**Post date:** [November 26, 2005, 12:51am UTC](https://www.ruby-forum.com/t/fun-with-ranges/48871/1 "2005-11-26T00:51:45Z")

</div>

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

Zounds,

Sam

---

<div class="post-metadata">

**Author:** ![sgentle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85f322/32.png) [@sgentle](https://www.ruby-forum.com/u/sgentle)\
**Post date:** [November 26, 2005, 1:28am UTC](https://www.ruby-forum.com/t/fun-with-ranges/48871/2 "2005-11-26T01:28:02Z")

</div>

Hi –

On Sat, 26 Nov 2005, Sam G. wrote:

> Hoorah! But not just that.  
> 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

---

<div class="post-metadata">

**Author:** ![sgentle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85f322/32.png) [@sgentle](https://www.ruby-forum.com/u/sgentle)\
**Post date:** [November 26, 2005, 1:36am UTC](https://www.ruby-forum.com/t/fun-with-ranges/48871/3 "2005-11-26T01:36:05Z")

</div>

On 11/26/05, David A. Black [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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)

C:\>ruby -ve ‘“a”…3’  
ruby 1.8.2 (2005-02-01) [i386-mswin32]  
-e:1: warning: useless use of … in void context

Strange…

weill samg$ ruby -ve ‘“a”…3’  
ruby 1.8.0 (2003-08-04) [i686-linux]  
-e:1: warning: useless use of … in void context  
-e:1: bad value for range (ArgumentError)

Double-strange… I wonder if it’s a windows thing or a version thing  
(and if so why it only pops up somewhere between 1.8.0 and 1.8.3).

Sam

---

<div class="post-metadata">

**Author:** ![sgentle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85f322/32.png) [@sgentle](https://www.ruby-forum.com/u/sgentle)\
**Post date:** [November 26, 2005, 1:44am UTC](https://www.ruby-forum.com/t/fun-with-ranges/48871/4 "2005-11-26T01:44:08Z")

</div>

Hi –

On Sat, 26 Nov 2005, Sam G. wrote:

> -e:1: warning: useless use of … in void context
> 
> Strange…
> 
> weill samg$ ruby -ve ‘“a”…3’  
> ruby 1.8.0 (2003-08-04) [i686-linux]  
> -e:1: warning: useless use of … in void context  
> -e:1: bad value for range (ArgumentError)
> 
> Double-strange… I wonder if it’s a windows thing or a version thing  
> (and if so why it only pops up somewhere between 1.8.0 and 1.8.3).

Interesting – it seems to be a 1.8.2 thing.

David
