From: Jacob Fugal Date: 2006-02-12T05:21:39+09:00 Subject: Re: Private methods - only available to oneself? On 2/11/06, Gene Tani wrote: > > Phrogz wrote: > > > > 2) If you are writing a class or module for use by others, they will > > have access to the source code, and could rewrite it to allow things > > you didn't intend. Use 'protected' and 'private' to indicate when the > > methods should be called under normal circumstances. But it's not a > > guarantee. > > There's a few loopholes around private and protected, e.g. subclass a > class with private methods and declare them public in the subclass, but > one of them is closed in 1.9, you can't #send private methods anymore > (ok, you can #funcall them, ...) An easier bypass, which I don't think[1] is closing in 1.9/2.0: reopen the class. galadriel:~$ cat > test.rb class Foo private def bar puts "bar" end end f = Foo.new begin f.bar rescue puts "Exception raised" end # ... later ... class Foo public :bar end g = Foo.new g.bar galadriel:~$ ruby test.rb Exception raised bar Jacob Fugal