Bird
0
0

Find the error in this Ruby code:

medium📝 Debug Q14 of 15
Ruby - Basics and Runtime
Find the error in this Ruby code:
def greet
  puts "Hello"
end

greet(1)
AArgumentError: wrong number of arguments
BNo error, prints Hello
CSyntaxError due to missing parentheses
DNameError: greet not defined
Step-by-Step Solution
Solution:
  1. Step 1: Check method definition

    greet is defined without parameters, so it expects zero arguments.
  2. Step 2: Check method call

    Calling greet(1) passes one argument, causing ArgumentError.
  3. Final Answer:

    ArgumentError: wrong number of arguments -> Option A
  4. Quick Check:

    Method params mismatch = ArgumentError [OK]
Quick Trick: Method defined with no params, calling with one causes error [OK]
Common Mistakes:
  • Thinking Ruby ignores extra arguments
  • Confusing syntax error with argument error
  • Assuming greet is undefined

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes