Can someone explain what the difference between false and nil this case is:
irb(main):008:0> Fixnum < Integer
=> true
irb(main):011:0> Integer < Fixnum
=> false
irb(main):012:0> String < Numeric
=> nil
I realize that "string开发者_高级运维s are not numbers" and that "not all integers are fixnums"
My thinking is naive and boolean. Either something includes something or not, true or false. But there appears to be a third option, like, "you are kidding, right?" ;-)
Can someone enlighten me?
The Object#<
method seems to act like this, given the code A < B
:
- If
A
is 'higher' in the inheritance chain (eg,B.kind_of?( A ) == true
) thentrue
. - If
A
is 'lower' in the inheritance chain (eg,A.kind_of?( B ) == true
) thenfalse
. - If
A
andB
have no relation, thennil
.
So, in your example. Integer
inherits from Fixnum
, obviously that implies that Fixnum
doesn't inherit from Integer
. And of course String
has nothing to do with Numeric
.
Here's some 'documentation' in the form of MRI source code :)
精彩评论