Bird
0
0

Which of the following best describes what happens if a Ruby method has no explicit return statement?

easy📝 Conceptual Q2 of 15
Ruby - Methods
Which of the following best describes what happens if a Ruby method has no explicit return statement?
AThe method returns nil by default
BThe method returns the last evaluated expression automatically
CThe method causes a syntax error
DThe method returns zero
Step-by-Step Solution
Solution:
  1. Step 1: Recall Ruby's implicit return behavior

    Ruby methods return the value of the last executed expression if no explicit return is used.
  2. Step 2: Eliminate incorrect options

    Methods do not return nil or zero by default, nor cause syntax errors without return.
  3. Final Answer:

    The method returns the last evaluated expression automatically -> Option B
  4. Quick Check:

    No explicit return = last expression returned [OK]
Quick Trick: No return? Ruby returns last expression automatically [OK]
Common Mistakes:
  • Assuming nil is returned without return
  • Expecting syntax error without return
  • Thinking zero is default return

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes