From: "Skye Shaw!@#$" Date: 2007-08-02T11:45:02+09:00 Subject: Re: Private methods not so private? On Aug 1, 5:42 pm, Daniel Berger wrote: > On Aug 1, 4:06 pm, Alex Young 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 is in C++ and Java, maybe even VB, if I recall... (I try not to recall VB). Well, maybe not a "security enforcement" but a visibility and/or invocation restriction. My JVM even gives me an IllegalAccessException when I try to access an private Method at runtime via reflection.