Bird
0
0

You want to call a private method secret on object obj. Which is the correct way to do this using send?

hard📝 Application Q8 of 15
Ruby - Metaprogramming Fundamentals
You want to call a private method secret on object obj. Which is the correct way to do this using send?
Aobj.call(:secret)
Bobj.secret
Cobj.public_send(:secret)
Dobj.send(:secret)
Step-by-Step Solution
Solution:
  1. Step 1: Understand private method access

    Private methods cannot be called normally from outside the class.
  2. Step 2: Using send to bypass visibility

    send can call private methods, unlike public_send which respects visibility.
  3. Final Answer:

    obj.send(:secret) -> Option D
  4. Quick Check:

    send can call private methods, public_send cannot [OK]
Quick Trick: Use send to call private methods, public_send respects visibility [OK]
Common Mistakes:
  • Using public_send to call private methods
  • Trying to call private method directly
  • Using undefined method call instead of send

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes