Bird
0
0

Identify the error in this Ruby method definition:

medium📝 Debug Q6 of 15
Ruby - Methods
Identify the error in this Ruby method definition:
def display(name:, age)
  puts "Name: #{name}, Age: #{age}"
end
AMethod should not have any arguments
BCannot mix keyword and positional arguments
CMissing colon after age keyword argument
DNo error, method is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check keyword argument syntax

    Both keyword arguments must have colons after their names in the definition.
  2. Step 2: Identify missing colon

    Age parameter lacks a colon, causing syntax error.
  3. Final Answer:

    Missing colon after age keyword argument -> Option C
  4. Quick Check:

    All keyword args need colons in definition [OK]
Quick Trick: Keyword args require colons after each name [OK]
Common Mistakes:
  • Omitting colon after keyword argument name
  • Mixing positional and keyword arguments incorrectly
  • Assuming no colon is needed for last keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes