Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean to compare classes with greater than `>` and less than `<` operators?

Tags:

ruby

I have not found any description for the operators >, <, >=, <= in the documentation for Object and Class.

String > Object      # => false
BasicObject > Object # => true
String > Integer     # => nil
like image 485
vovan Avatar asked Dec 18 '22 18:12

vovan


1 Answers

When class level comparison is done, it looks for hierarchy/relationship.

String > Object returns false because Object is ancestor for String class.

Similar will be followed for this hierarchy Object -> Numeric -> Integer

String > Integer returns nil because both classes do not come in same hierarchy/relationship.

like image 63
ray Avatar answered May 22 '23 13:05

ray