Bird
0
0

What does adding self. before a method name inside a Ruby class do?

easy📝 Conceptual Q11 of 15
Ruby - Class Methods and Variables
What does adding self. before a method name inside a Ruby class do?
ADefines a method that can only be called inside other methods
BMakes the method private and inaccessible outside the class
CMakes the method an instance method, callable on objects
DMakes the method a class method, callable on the class itself
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of self. in method definition

    In Ruby, prefixing a method name with self. inside a class defines it as a class method.
  2. Step 2: Identify how class methods are called

    Class methods are called on the class itself, not on instances of the class.
  3. Final Answer:

    Makes the method a class method, callable on the class itself -> Option D
  4. Quick Check:

    self.method_name defines class method [OK]
Quick Trick: Remember: self.method means class method, no instance needed [OK]
Common Mistakes:
  • Thinking self. makes method private
  • Confusing class methods with instance methods
  • Assuming self. methods are only for internal use

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes