On Aug 1, 4:06 pm, Alex Young <a... / blackkettle.org> wrote:
> Frank Meyer wrote:
> > Hello,
> > I'm using Ruby 1.8.2 and I'm reading the book "Programming Ruby 2nd
> > edition". In this book they say, that Ruby implements private methods by
> > not allowing another receiver than "self". After reading this, I tried
> > the following:
>
> > class Test
> >  private
> >  def print_hello
> >   puts "Hello everyone!"
> >  end
> > end
>
> > t = Test.new
> > t.send( "print_hello" )
>
> > This program runs just fine and prints "Hello everyone!".
>
> > Is this behaviour to be expected?
>
> Yes - send trumps private.  Private in Ruby is more of a guideline than
> a rule.

It's a guideline in any language.

I think people tend to think of 'private' as some sort of security
enforcement. It's not. It just means, "You aren't supposed to access
this method directly. If you go out of your way to do so, I am not
responsible for the consequences".

The advantage of allowing send to access private methods is that it
allows you to test private methods. :)

Regards,

Dan