什么是两者之间的区别?
case item.class
when MyClass
# do something here
when Array
# do something different here
when String
# do a third thing
end
而且
case item.class
when MyClass.class
# do something here
when Array.class
# do something different here
when String.class
# do a third thing
end
由于某些原因,第一个有时有效而第二个无效,而其他时候,第二个有效而第一个无效。为什么?哪种方法是“正确”的?
MyClass === obj
使用 Module#=== 方法来检查obj
是否是MyClass
的实例。 - builder-7000