title: Clarify definitions of "private" and "protected" in Ruby?
body: <blockquote>
  <p>If a method is protected, it may be called by <em>any</em> instance of the defining
  class or its subclasses. If a method is private, it may be called only within
  the context of the calling object—it is never possible to access another
  object’s private methods directly, even if the object is of the same class
  as the caller.</p>
  <p>—<em>Programming Ruby</em>, &quot;Classes, Objects, and Variables: <a href="https://ruby-doc.com/docs/ProgrammingRuby/html/tut_classes.html#s4" rel="nofollow noreferrer">Access Control</a>&quot;</p>
  </blockquote>
  <p>This definition i got from net  when searching for the difference between private and protected methods in ruby.</p>
  <p>I have 2 doubts in this</p>
  <pre><code>class Abc
    def abc
      xyz
    end
   protected 
    def xyz
      p &quot;hai&quot;
    end
  end
  
  a=Abc.new
  a.abc
  </code></pre>
  <p>In this i am calling xyz implicitly on object a, this is how i will call xyz even if it is private.So &quot;it may be called by any instance of the defining class&quot; what does this mean ?????</p>
  <p>Secondly,</p>
  <pre><code> class Abc
     def abc(obj)
       obj.xyz1
       obj.xyz2
       obj.xyz3
     end
   end
  
   class Xyz
     def xyz1
       p &quot;called&quot;
     end
  
    private 
     def xyz2
       p &quot;called&quot;
     end
  
    protected
     def xyz3
       p &quot;called&quot;
     end
  
   end
  
   a=Abc.new
   b=Xyz.new
   a.abc(b)
  </code></pre>
  <p>In this i can call obj b's xyz1 method on object a.But i cant call obj b's protected xyz3 and private method xyz2 method on object a.So &quot;it is never possible to access another object’s private methods directly, even if the object is of the same class as the caller.&quot; what does this exact mean???</p>
  <p>can anybody help me to understand this one with  better examples????</p>