Bird
0
0

What is the error in this Ruby code snippet?

medium📝 Debug Q6 of 15
Ruby - Metaprogramming Fundamentals
What is the error in this Ruby code snippet?
class Vehicle
  define_method(:move) do
    puts 'Moving'
  end

  define_method(:stop)
    puts 'Stopped'
  end
end
AMissing block for second define_method call
BMethod names must be strings, not symbols
CCannot use define_method inside class
DExtra end keyword after first define_method
Step-by-Step Solution
Solution:
  1. Step 1: Review define_method syntax

    It requires a block after the method name.
  2. Step 2: Identify problem

    The second define_method(:stop) lacks a block and uses incorrect syntax.
  3. Final Answer:

    Missing block for second define_method call -> Option A
  4. Quick Check:

    define_method must have a block [OK]
Quick Trick: define_method always needs a block [OK]
Common Mistakes:
  • Using parentheses without block
  • Passing method name as string or symbol confusion
  • Misplacing end keywords

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes