I’m reading Why’s guide, and trying some of the commands in the ruby terminal side-by-side. One thing doesn’t match up. I’m running Ruby 1.9.3.
In the book it says a valid command is:
if 1890..1913 === 1895
echo "works"
end
However, when I do this, it just gives me
warning: (irb):27: warning: integer literal in conditional range
=> nil
Some more fascinating experiments
1895..1913 === 1895
> ArgumentError: bad value for range
from (irb):31
from /usr/bin/irb:12:in `<main>'
x = 1895..1913
x === 1895
> true
This is interesting because (coming from python) I would have thought the last two executions were identical, however, it seems not so. I wonder if anyone could reveal more insight into why all those experiments failed, and how the === works.
1895..1913 === 1895is the same as1895..(1913 === 1895), and what you want is(1895..1913) === 1895.See Ruby Operator Precedence.