Bird
0
0

Identify the error in this Ruby method:

medium📝 Debug Q6 of 15
Ruby - Methods
Identify the error in this Ruby method:
def print_args(*args)
  puts args
end

print_args(1, 2, 3)
ANo error; method works correctly
BShould use puts *args instead of puts args
CMissing parentheses in method call
Dargs is not defined
Step-by-Step Solution
Solution:
  1. Step 1: Understand what puts does with an array

    Calling puts args prints each element on a new line.
  2. Step 2: Check for syntax or runtime errors

    There is no syntax error or undefined variable; the method works as intended.
  3. Final Answer:

    No error; method works correctly -> Option A
  4. Quick Check:

    puts prints each array element on separate lines [OK]
Quick Trick: puts array prints each element on its own line [OK]
Common Mistakes:
  • Thinking puts args prints array as one line
  • Believing *args must be splatted in puts
  • Assuming missing parentheses cause error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes