Bird
0
0

Why does Ruby use implicit return of the last expression in methods?

hard📝 Conceptual Q10 of 15
Ruby - Methods
Why does Ruby use implicit return of the last expression in methods?
ATo simplify code by avoiding explicit return statements
BBecause explicit return is not allowed in Ruby
CTo force methods to always return nil
DTo make methods run faster
Step-by-Step Solution
Solution:
  1. Step 1: Understand Ruby design philosophy

    Ruby aims for readable and concise code, so implicit return avoids unnecessary return keywords.
  2. Step 2: Evaluate options

    Explicit return is allowed, methods do not always return nil, and implicit return does not affect speed significantly.
  3. Final Answer:

    To simplify code by avoiding explicit return statements -> Option A
  4. Quick Check:

    Implicit return improves code simplicity [OK]
Quick Trick: Implicit return keeps Ruby code clean and simple [OK]
Common Mistakes:
  • Thinking explicit return is disallowed
  • Believing methods always return nil
  • Assuming implicit return improves speed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes