Bird
0
0

Identify the error in this Ruby code:

medium📝 Debug Q6 of 15
Ruby - Classes and Objects

Identify the error in this Ruby code:

class Car
  def start
    puts 'Starting engine'
  # missing end here

car = Car.new
car.start
ANameError for undefined variable car
BNo error, code runs fine
CSyntaxError due to missing 'end' for method
DRuntimeError because start method is empty
Step-by-Step Solution
Solution:
  1. Step 1: Check method definition completeness

    The method start is missing its closing end keyword.
  2. Step 2: Understand Ruby syntax rules

    Every method must end with end. Missing it causes a SyntaxError.
  3. Final Answer:

    SyntaxError due to missing 'end' for method -> Option C
  4. Quick Check:

    Missing 'end' causes SyntaxError [OK]
Quick Trick: Always close methods with 'end' to avoid syntax errors [OK]
Common Mistakes:
  • Forgetting 'end' after method
  • Assuming code runs without errors
  • Confusing runtime errors with syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes