3 ms·
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.
by teraflop 13y ago
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.
- xentronium 13y agop..q is a fairly common math notation synonymous with [p,q]. Although, p...q is not very obvious, indeed.
- marcosdumay 13y agoWell, 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).
- kintamanimatt 13y agoI 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"!