Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

From the perspective of someone who doesn't know Ruby, the fact that a[1..10] is longer than a[1...10] is pretty counterintuitive.


I found it quite unintuitive too at first. My way of remembering it was to think of the distance between the endpoints. The first example is inclusive because it's closer and the endpoint is "included" whereas the second range endpoint is shunned and shoved further away and is exclusive because it's "excluded"!


p..q is a fairly common math notation synonymous with [p,q].

Although, p...q is not very obvious, indeed.


Well, they aren't synonymous in Ruby. It's [p,q] operator is also not intuitive for me.

But then, "not intuitive" just means I'll spend a few minutes more learning the language because of it (except in C++, where it means many hours).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: