Ben Bleything wrote:
> On Thu, Aug 02, 2007, Frank Meyer wrote:
>> 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 bypasses protection levels, for reasons I'm not really clear
> on.  If I were to hazard a guess, it would be that what you send is
> eval'ed inside the context of the object, thereby making self the
> receiver, but that's a total guess.
> 
> Test.new.print_hello will cause the error you expect.
> 
> As a sidenote, upgrade your ruby ;)
> 
> Ben
> 
> 

Ben,

It is always possible to run private methods, change class variables, 
etc. The way to do it is to reopen the class (or add an instance method) 
that calls the private method or sets/gets the variable we need. Since 
it's possible, why not make it easier? Ruby tries not to impose on what 
the user can do, so we have foo.send, foo.instance_variable_set, and 
foo.instance_variable_get.

Dan