Bird
0
0

What is wrong with this Ruby class definition?

medium📝 Debug Q7 of 15
Ruby - Ecosystem and Best Practices
What is wrong with this Ruby class definition?
class employee
  def initialize(salary)
    @salary = salary
  end
end

e = employee.new(5000)
AClass name should start with a capital letter according to Ruby conventions
BInstance variable @salary is not initialized properly
CMethod initialize should be named differently
DObject creation syntax is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Review class naming conventions

    Ruby classes should be named using CamelCase starting with a capital letter.
  2. Step 2: Analyze the class name

    The class is named employee starting with a lowercase letter, which violates convention.
  3. Step 3: Check other parts

    Instance variable and object creation are correct.
  4. Final Answer:

    Class name should start with a capital letter according to Ruby conventions -> Option A
  5. Quick Check:

    Class names must be CamelCase starting uppercase [OK]
Quick Trick: Class names start with uppercase CamelCase [OK]
Common Mistakes:
  • Thinking instance variables need special initialization
  • Believing object creation syntax is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes