Bird
0
0

Which of the following Ruby method definitions correctly uses implicit return?

easy📝 Syntax Q12 of 15
Ruby - Methods
Which of the following Ruby method definitions correctly uses implicit return?
Adef add(a, b) a + b end
Bdef add(a, b) return a + b puts 'done' end
Cdef add(a, b) puts a + b end
Ddef add(a, b) a + b; return end
Step-by-Step Solution
Solution:
  1. Step 1: Check each method for implicit return usage

    def add(a, b) a + b end returns the last expression a + b implicitly without return.
  2. Step 2: Analyze other options

    def add(a, b) return a + b puts 'done' end uses explicit return, def add(a, b) puts a + b end returns nil because puts returns nil, def add(a, b) a + b; return end has return with no value, returning nil.
  3. Final Answer:

    def add(a, b) a + b end -> Option A
  4. Quick Check:

    Implicit return = last expression value [OK]
Quick Trick: Implicit return means last line's value is returned [OK]
Common Mistakes:
  • Confusing puts output with return value
  • Using return unnecessarily
  • Returning nil unintentionally

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes