Austin Ziegler wrote:
> On 8/4/05, Stefan Achatz <erazor / mitochondrien.de> wrote:
> > Ryan Leavengood wrote:
> >> Stefan Achatz said:
> > It's hard to understand, why i can't access the private singleton
> > from Myclass anymore:
> > class Myclass
> >   def testing
> >     self.bar
> >   end
> >   def self.bar
> >   end
> >   class << self
> >     private :bar
> >   end
> > end
>
> > I should say that i'm coming from c++ and it seems im lacking some
> > understanding in the differences between static methods in c++ and
> > singleton methods in ruby.
>
> They're not at all related. They look like they might be, but
> they're not.
>
> By making Myclass.bar private, you are making it so that it can only
> be called within its *self*, which is Myclass[1]. Therefore,
> instances of Myclass cannot call Myclass.bar because their *self* is
> not Myclass, but an instance of Myclass.

To be more explicit, there are two reasons that won't work:

1. The method #testing is an instance method. You can't call class
methods as "self.whatever" in an instance method. It would be
"self.class.whatever".

2. The meaning of "private" in Ruby is "cannot be called with an
explicit receiver." That is, you would have to call "self.bar" as just
"bar" in your test method.