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.