0
0
Rubyprogramming~5 mins

Subclass with < operator in Ruby - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the < operator mean when used between two classes in Ruby?
The &lt; 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 &lt; Animal; end</code><br>What is the result of <code>Dog &lt; 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 &lt; operator be used to check subclass relationships between unrelated classes?
No. If the classes are unrelated, the &lt; operator returns nil, meaning no subclass relationship exists.
Click to reveal answer
What does Child < Parent return if Child inherits from Parent?
ARaises an error
Bfalse
Cnil
Dtrue
What does Parent < Child return if Child inherits from Parent?
Atrue
Bnil
Cfalse
DRaises an error
What is the result of String < Numeric in Ruby?
Anil
Btrue
Cfalse
DRaises an error
Which operator checks subclass relationships between classes in Ruby?
A==
B&gt;
C&lt;
D!=
If class Cat < Animal; end, what does Cat < Animal return?
Atrue
BRaises an error
Cnil
Dfalse
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.