Bird
0
0

Which of the following is a valid way to create a new class named Animal using Class.new?

easy📝 Conceptual Q2 of 15
Ruby - Metaprogramming Fundamentals
Which of the following is a valid way to create a new class named Animal using Class.new?
AAnimal = Class.create
BAnimal = Class.new
CAnimal = new Class()
DAnimal = Class.define
Step-by-Step Solution
Solution:
  1. Step 1: Recall Ruby syntax for dynamic class creation

    The correct syntax is Class.new assigned to a constant to name the class.
  2. Step 2: Evaluate options

    Only Animal = Class.new is valid Ruby syntax; others are invalid method calls or syntax.
  3. Final Answer:

    Animal = Class.new -> Option B
  4. Quick Check:

    Correct syntax for dynamic class = Class.new assigned [OK]
Quick Trick: Assign Class.new to a constant to name the class [OK]
Common Mistakes:
  • Using JavaScript-like syntax (new Class())
  • Calling non-existent methods like Class.create
  • Confusing class creation with method definition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes