Recall & Review
beginner
What does the < operator mean when used between two classes in Ruby?
The < operator checks if the left class is a subclass of the right class. It returns true if the left class inherits from the right class, otherwise nil.Click to reveal answer
beginner
How can you check if class B is a subclass of class A in Ruby?You can write
B < A. If B inherits from A, this expression returns true.Click to reveal answer
beginner
Given <br><code>class Animal; end<br>class Dog < Animal; end</code><br>What is the result of <code>Dog < Animal</code>?It returns true because Dog is a subclass of Animal.Click to reveal answer
beginner
What will
Animal < Dog return given the previous classes?It returns nil because Animal is not a subclass of Dog; it is the other way around.Click to reveal answer
intermediate
Can the < operator be used to check subclass relationships between unrelated classes?No. If the classes are unrelated, the < operator returns nil, meaning no subclass relationship exists.Click to reveal answer
What does
Child < Parent return if Child inherits from Parent?✗ Incorrect
If Child inherits from Parent, Child < Parent returns true.
What does
Parent < Child return if Child inherits from Parent?✗ Incorrect
Parent is not a subclass of Child, so Parent < Child returns nil.
What is the result of
String < Numeric in Ruby?✗ Incorrect
String and Numeric are unrelated classes, so the < operator returns nil.
Which operator checks subclass relationships between classes in Ruby?
✗ Incorrect
The < operator checks if one class is a subclass of another.
If
class Cat < Animal; end, what does Cat < Animal return?✗ Incorrect
Cat inherits from Animal, so Cat < Animal returns true.
Explain how the < operator works to check subclass relationships in Ruby.
Think about inheritance and how Ruby checks if one class inherits from another.
You got /3 concepts.
Describe what happens when you compare two unrelated classes using the < operator in Ruby.
Consider what Ruby returns when no inheritance link exists.
You got /3 concepts.