Ruby includes false and nil return

Can someone explain what is the difference between false and nil in this case:

irb(main):008:0> Fixnum < Integer
=> true
irb(main):011:0> Integer < Fixnum
=> false
irb(main):012:0> String < Numeric
=> nil

I understand that "strings are not numbers" and that "not all integers are fixnums"

My thinking is naive and logical. Either something includes something, or not, true or false. But there seems to be a third option, for example: "You're kidding, are you?"; -)

Can someone enlighten me?

+3
source share
1 answer

The method Object#<seems to act as follows, given the code A < B:

  • If Ais the "highest" in the inheritance chain (e.g. B.kind_of?( A ) == true), then . true
  • A "" (, A.kind_of?( B ) == true), false.
  • A B , nil.

, . Integer Fixnum, , , Fixnum Integer. , , String Numeric.

'documentation' MRI:)

+9

Source: https://habr.com/ru/post/1722263/


All Articles