"Ruby, in an adorable little attempt to wear big-boy pants, is turning this expression into the following pseudo-code"
Is the condescending tone necessary?
An alternative:
"Ruby turns this expression into the following pseudo-code"
Is the condescending tone necessary?
An alternative:
"Ruby turns this expression into the following pseudo-code"
Better pseudo code would be
1.lt(2).lt(3)
In fact, this is correct (albeit ungainly) ruby code 1.<(2) # true
and so 1.<(2).<(3) # Say wha ... ?
makes no sense.[0]: Yes, a cheap shot.
Those familiar with the mathematical notation would think:
1. '1 < 2 < 3' parses to '(1 < 2) and (2 < 3)'.
2. '3 - 4 - 5' parses to '(3 - 4) - 5'.
3. '3 ^ 4 ^ 5' parses to '3 ^ (4 ^ 5)'.
Ruby's convention is clever, but ultimately wrong, and this is one of the cases.And 1 < 2 evaluates to true. What else would it evaluate to?
That leaves (true < 3)
Which fails. This isn't a mistake by ruby. When you chain methods you have to think about what they return.
And the issue here isn't associativity.
I actually think that a trained mathematician would have no idea what to do with 3 ^ 4 ^ 5. It's a completely ambiguous statement and has no proper mathematical parsing.