Bird
0
0

In Ruby, if a method does not explicitly use return, what value does it provide when called?

easy📝 Conceptual Q1 of 15
Ruby - Methods
In Ruby, if a method does not explicitly use return, what value does it provide when called?
AThe first variable assigned in the method
BAlways <code>nil</code>
CThe value of the last evaluated expression inside the method
DThe method name as a string
Step-by-Step Solution
Solution:
  1. Step 1: Understand Ruby's method return behavior

    Ruby methods return the value of the last evaluated expression if no explicit return is used.
  2. Step 2: Analyze the options

    Only The value of the last evaluated expression inside the method correctly describes this behavior.
  3. Final Answer:

    The value of the last evaluated expression inside the method -> Option C
  4. Quick Check:

    Method returns last expression value [OK]
Quick Trick: Ruby methods return last expression value by default [OK]
Common Mistakes:
  • Assuming methods return nil if no return is used
  • Thinking the first assigned variable is returned
  • Believing method name is returned

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes