Bird
0
0

Identify the error in this Ruby method declaration:

medium📝 Debug Q14 of 15
Ruby - Methods
Identify the error in this Ruby method declaration:
def say_hello
  puts "Hello"
AMissing 'end' keyword to close method
BMissing parentheses after method name
CIncorrect use of puts inside method
DMethod name cannot have underscore
Step-by-Step Solution
Solution:
  1. Step 1: Check method structure

    Ruby methods must start with def and end with end. This code misses the end keyword.
  2. Step 2: Identify the missing part

    Without end, Ruby will raise a syntax error because the method is not properly closed.
  3. Final Answer:

    Missing 'end' keyword to close method -> Option A
  4. Quick Check:

    Every method needs 'end' [OK]
Quick Trick: Always close methods with 'end' keyword [OK]
Common Mistakes:
MISTAKES
  • Forgetting 'end' after method body
  • Thinking parentheses are mandatory
  • Assuming underscores are invalid in names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes