问题描述
我在读为什么指南,并尝试一些命令在Ruby终端侧并排。有一件事不匹配。我跑的Ruby 1.9.3。
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 === 1895年
相同 1895年。 (1913年=== 1895)
,和你想要的是(1895..1913)=== 1895年
。
1895..1913 === 1895
is the same as 1895..(1913 === 1895)
, and what you want is (1895..1913) === 1895
.
请参阅。
这篇关于如何Ruby的范围和三重等于(===)工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!