Bird
0
0

Why does Ruby implement operators as methods instead of special syntax or keywords?

hard📝 Conceptual Q10 of 15
Ruby - Operators and Expressions
Why does Ruby implement operators as methods instead of special syntax or keywords?
ATo prevent users from using operators in their own classes.
BBecause Ruby does not support special syntax for operators.
CTo allow flexibility and polymorphism by letting classes define operator behavior.
DBecause operators are slower as methods.
Step-by-Step Solution
Solution:
  1. Step 1: Understand Ruby's design philosophy

    Ruby emphasizes flexibility and object-oriented design.
  2. Step 2: Reason about operators as methods

    Implementing operators as methods allows classes to customize behavior (polymorphism).
  3. Final Answer:

    To allow flexibility and polymorphism by letting classes define operator behavior. -> Option C
  4. Quick Check:

    Operators as methods enable polymorphism = A [OK]
Quick Trick: Operators as methods enable flexible, custom behavior [OK]
Common Mistakes:
MISTAKES
  • Thinking Ruby lacks special syntax
  • Believing operators are restricted
  • Assuming methods are slower and less flexible

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes