tags:

views:

83

answers:

1

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 "strings 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?

+6  A: 

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) then true.
  • If A is 'lower' in the inheritance chain (eg, A.kind_of?( B ) == true) then false.
  • If A and B have no relation, then nil.

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 :)

thenduks