From: Justin Collins Date: 2006-12-15T12:09:07+09:00 Subject: Re: Why is define_method private? Plus, what's the point of private methods? Daniel Finnie wrote: > Also, a quick philosophy question: > What is the point of private methods if you can bypass their private > status so easily? I know it isn't meant as a security measure or > anything but it just seems silly. The only reason I can think of is > having too many methods cluttering up the RDocs if everything was > public, but this is easily solved by having a method being private > just meaning that it doesn't show up in the docs. > > The same arguments apply to protected methods also, IMO. > > Now, I know someone will mention that Ruby 1.9 won't allow calling > private methods with an explicit receiver through send, but, according > to my "research," Kernel#__send and Kernel#funcall will. > (http://eigenclass.org/hiki.rb?Changes+in+Ruby+1.9#l22) > > Thanks, > Dan Finnie About private methods...this is something that comes up every now and then. In my very humble opinion, private methods are just a polite way of separating the API methods from the methods expected to be used only by the object itself. No, it doesn't stop anyone from using them, really, but if you find yourself going against the intentions of the original programmer, you might stop a moment and think about why you are having to do that. Is it a poor API, or is there a better way to do what you are trying to do? In other words, private methods are, to me, just a nicety, not something integral to the language. I draw that conclusion from the looseness of their enforcement and the lack of emphasis placed upon them. This happens a lot in Ruby. It let's you do what you want, if you really want. I think that's nice of it. -Justin