Bird
0
0

Identify the error in this Ruby code:

medium📝 Debug Q6 of 15
Ruby - Basics and Runtime
Identify the error in this Ruby code:
def add(a, b)
  a + b
end

puts add(5)
ASyntax error in method definition
BMissing second argument in method call
CUndefined method 'add'
DNo error, outputs 5
Step-by-Step Solution
Solution:
  1. Step 1: Check method definition and call

    Method add expects two arguments, but only one is given in call.
  2. Step 2: Identify runtime error

    Ruby raises ArgumentError for wrong number of arguments.
  3. Final Answer:

    Missing second argument in method call -> Option B
  4. Quick Check:

    Argument count mismatch = Error [OK]
Quick Trick: Method arguments must match when called [OK]
Common Mistakes:
  • Assuming missing argument defaults to nil
  • Thinking syntax error exists
  • Believing method is undefined

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes