Bird
0
0

Which statement about Class.new in Ruby is TRUE?

hard📝 Conceptual Q10 of 15
Ruby - Metaprogramming Fundamentals
Which statement about Class.new in Ruby is TRUE?
AMethods defined inside <code>Class.new</code> block are class methods by default
B<code>Class.new</code> cannot accept a superclass argument
CYou cannot define instance methods inside <code>Class.new</code> block
D<code>Class.new</code> always creates anonymous classes unless assigned to a constant
Step-by-Step Solution
Solution:
  1. Step 1: Understand naming of classes created by Class.new

    Classes created by Class.new are anonymous unless assigned to a constant.
  2. Step 2: Evaluate other statements

    Class.new can accept superclass; methods inside block are instance methods by default; instance methods can be defined inside block.
  3. Final Answer:

    Class.new always creates anonymous classes unless assigned to a constant -> Option D
  4. Quick Check:

    Anonymous class unless named by constant [OK]
Quick Trick: Class.new creates anonymous class unless assigned [OK]
Common Mistakes:
  • Thinking Class.new creates named classes automatically
  • Assuming methods inside block are class methods
  • Believing Class.new cannot take superclass

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes