Bird
0
0

Which of the following best explains why Ruby allows redefining operators like +?

easy📝 Conceptual Q2 of 15
Ruby - Operators and Expressions
Which of the following best explains why Ruby allows redefining operators like +?
ABecause operators are fixed and cannot be changed.
BBecause operators are methods, so you can define their behavior per class.
CBecause Ruby uses macros to replace operators at compile time.
DBecause operators are global functions shared by all classes.
Step-by-Step Solution
Solution:
  1. Step 1: Recall operator method behavior

    Operators in Ruby are methods, so their behavior depends on the class.
  2. Step 2: Understand method overriding

    You can redefine these methods in your own classes to customize operator behavior.
  3. Final Answer:

    Because operators are methods, so you can define their behavior per class. -> Option B
  4. Quick Check:

    Operator redefining = A [OK]
Quick Trick: Operators are methods you can customize per class [OK]
Common Mistakes:
  • Thinking operators are fixed keywords
  • Confusing compile-time macros with runtime methods
  • Assuming operators are global functions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes