[ Content | View menu ]

Ruby Range Mnemonic

Mark Mzyk | January 11, 2009

While currently working to learn Ruby, I keep forgetting the meaning of each of the range syntaxes, the difference between .. and … .

I’ve developed a mnemonic to help me.

1..10 is the Ruby inclusive syntax, so 10 would be included in the values.

1…10 is the Ruby exclusive syntax, so 10 would be excluded from the values.

How to remember this?

With … the 10 is farther way, so it’s excluded from the party.

I’m sure over time I’ll just have the difference hardwired into my brain, but for now this helps me to remember.

Filed in: Programming.


  1. Comment by Dan Bernier:

    I know it’s old news, but _why’s (poignant) guide to ruby has lots of these mnemonics. When I was first learning ruby, it was really helpful. Especially chapter 3: http://poignantguide.net/ruby/chapter-3.html

    January 12, 2009 @ 08:09
  2. Comment by Mark:

    I had no idea, so it isn’t old news to me. I know of _why’s poignant guide, but have never read it. I’ll have to check it out. Thanks Dan.

    Do you have any favorite Ruby mnemonics you want to pass on?

    January 12, 2009 @ 08:54