奇怪的行为:Fixnum 值与数字不匹配,以防...时
我有一段代码,看起来像:
case n
when Numeric
(do this)
else
(do that)
end
但当 n 是 Fixnum 时,它正在执行“(do that)”。我在(执行此操作)处设置了一个断点,并执行“pp n.class”生成“Fixnum”的输出。我还尝试了“pp Numeric === n”,它产生“false”,而“pp Numeric === 5”,产生“true”。 n 如何报告一类 Fixnum 却未通过测试“Numeric === n”?
I have a piece of code that looks like:
case n
when Numeric
(do this)
else
(do that)
end
but it is executing "(do that)" when n is a Fixnum. I set a breakpoint at the (do that) and did "pp n.class" producing output of "Fixnum". I also tried "pp Numeric === n" which produced "false", and "pp Numeric === 5", producing "true". How can n be reporting a class of Fixnum and yet fail the test "Numeric === n"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定您的
n
确实是Fixnum
吗?只是问一下,因为您还提到
Numeric === n
返回 false,这是不应该的:您能否发布一段更大的代码片段或其他内容(我知道您说过
n .class
是Fixnum
,但代码肯定不会那样工作)。Are you sure your
n
is indeed aFixnum
?Just asking cause you also mentioned that
Numeric === n
returned false, which it shouldn't:Can you maybe post a somewhat bigger snippet of code or something (I know you said that
n.class
isFixnum
, but the code certainly doesn't behave that way).