# Private and self

**URL:** <https://www.ruby-forum.com/t/private-and-self/65655>\
**Category:** Ruby\
**Created:** [August 20, 2006, 8:16am UTC](https://www.ruby-forum.com/t/private-and-self/65655 "2006-08-20T08:16:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marinho\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@Marinho\_T](https://www.ruby-forum.com/u/Marinho_T)\
**Post date:** [August 20, 2006, 8:16am UTC](https://www.ruby-forum.com/t/private-and-self/65655/1 "2006-08-20T08:16:21Z")

</div>

Why doesnÂ´t the call with self doesnÂ´t work ? I know that private means  
private to the object, but the private methode call is within the same  
object (at least itÂ´s what i think). DoesnÂ´t self mean “the object  
himself” ? So why is this error occuring ?

test.rb:14:in `with_self': private method`private\_methode’ called for  
#PrivateTest:0x2aaaaab00508 (NoMethodError)

```auto
class PrivateTest

def private_methode()
puts("I am private")
end

def without_self()
puts("without self")
private_methode()
end

def with_self()
puts("with self")
self.private_methode()
end

private :private_methode
end

test = PrivateTest.new
test.without_self()
test.with_self()
```

---

<div class="post-metadata">

**Author:** ![Marinho\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@Marinho\_T](https://www.ruby-forum.com/u/Marinho_T)\
**Post date:** [August 20, 2006, 5:32pm UTC](https://www.ruby-forum.com/t/private-and-self/65655/2 "2006-08-20T17:32:55Z")

</div>

On 8/20/06, Marinho T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Why doesnÂ´t the call with self doesnÂ´t work ? I know that private means  
> private to the object, but the private methode call is within the same  
> object (at least itÂ´s what i think). DoesnÂ´t self mean “the object  
> himself” ? So why is this error occuring ?

\>

Just quoting from the Pixcake (or was it Pickaxe 😉 book  
[…]

- _Private methods_ cannot be called with an explicit receiver.  
Because you cannot specify an object when using them, private methods  
can be  
called only in the defining class and by direct descendents within  
that same  
object.

The difference between `protected'' and `private’’ is fairly subtle,  
and  
is different in Ruby than in most common OO languages. If a method is  
protected, it may be called by _any_ instance of the defining class or  
its  
subclasses  
[…]  
So in Ruby surprisingly one canot indicate an explicit reveiver to a  
private  
method. Even if it is self which comes to a surprise at the beginning.  
If I understand correctly this might change in Ruby2, and maybe  
ritefully so  
;).

## Cheers Robert

Deux choses sont infinies : l’univers et la bÃªtise humaine ; en ce qui  
concerne l’univers, je n’en ai pas acquis la certitude absolue.

- Albert Einstein
