Bird
0
0

Identify the error in this Ruby code:

medium📝 Debug Q6 of 15
Ruby - Basics and Runtime
Identify the error in this Ruby code:
value = 10
puts value.class()
ARuntimeError due to missing variable
BNo error, code runs fine
CNoMethodError because class is not a method
DSyntaxError due to parentheses after class
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of class method call

    In Ruby, calling class with or without parentheses is valid syntax.
  2. Step 2: Confirm code runs without error

    The code prints the class of value (which is Integer) without any error.
  3. Final Answer:

    No error, code runs fine -> Option B
  4. Quick Check:

    Calling .class() is valid syntax [OK]
Quick Trick: Parentheses optional when calling methods without arguments [OK]
Common Mistakes:
  • Thinking parentheses cause syntax errors
  • Confusing class keyword with method call
  • Expecting errors from valid syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes