Bird
0
0

What does the self keyword represent inside an instance method in Ruby?

easy📝 Conceptual Q11 of 15
Ruby - Classes and Objects
What does the self keyword represent inside an instance method in Ruby?
AThe superclass of the current class
BThe class itself
CA global variable
DThe current instance (object) of the class
Step-by-Step Solution
Solution:
  1. Step 1: Understand instance methods context

    Inside an instance method, the code runs for a specific object created from the class.
  2. Step 2: Identify what self points to

    In this context, self refers to that specific object (instance) running the method.
  3. Final Answer:

    The current instance (object) of the class -> Option D
  4. Quick Check:

    self in instance method = instance [OK]
Quick Trick: Inside instance methods, think "self" means the object itself [OK]
Common Mistakes:
  • Confusing self with the class inside instance methods
  • Thinking self is a global or class variable
  • Assuming self is always the class

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes