Just use the <
operator
B < A # => true
A < A # => false
or use the <=
operator
B <= A # => true
A <= A # => true
Also available:
B.ancestors.include? A
This differs slightly from the (shorter) answer of B < A
because B
is included in B.ancestors
:
B.ancestors
#=> [B, A, Object, Kernel, BasicObject]
B < B
#=> false
B.ancestors.include? B
#=> true
Whether or not this is desirable depends on your use case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With