Bird
0
0

Identify the error in this Ruby code snippet:

medium📝 Debug Q14 of 15
Ruby - Ecosystem and Best Practices
Identify the error in this Ruby code snippet:
class myclass
  def initialize
    @name = "Ruby"
  end
end
AClass keyword should be lowercase.
BInstance variable @name is not allowed.
CMissing parentheses in initialize method.
DClass name should be in CamelCase, not lowercase.
Step-by-Step Solution
Solution:
  1. Step 1: Check class naming convention

    Ruby classes must be named using CamelCase starting with a capital letter.
  2. Step 2: Identify the incorrect class name

    'myclass' is all lowercase, which breaks convention and can cause confusion.
  3. Final Answer:

    Class name should be in CamelCase, not lowercase. -> Option D
  4. Quick Check:

    Class names = CamelCase = Class name should be in CamelCase, not lowercase. [OK]
Quick Trick: Class names always start with a capital letter [OK]
Common Mistakes:
  • Using lowercase for class names
  • Thinking instance variables are invalid
  • Believing parentheses are mandatory for initialize

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes