From: Gene Tani Date: 2005-10-27T05:42:04+09:00 Subject: Re: how private is private in ruby? the other way to subvert private (or protected) declarations is to subclass the class with the private methods, and declare the superclass' private method public in the subclass. Jeremy Kemper wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Oct 26, 2005, at 12:32 PM, Peter Ertl wrote: > > Why is this allowed / possible? > > > > class MyUltraSecretKeystore > > private > > def key > > return "nobody-should-read-this-ever" > > end > > end > > > > ks = MyUltraSecretKeystore.new > > > > $ puts ks.send(:key) > > > >> "nobody-should-read-this-ever" > >> > > > > *yuk* > > > > so I can just use [public] for _everything_ as well, right? > > > In current Ruby 1.9 you may not send private methods. I don't know > whether this is an experiment or a permanent restriction. > > Regardless, you may ks.instance_eval { key } anyway, though in > this case at least you have $SAFE at your disposal. > > jeremy > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.2 (Darwin) > > iD8DBQFDX+CVAQHALep9HFYRAlV3AJ9BEHcb5Xmb8qRLS09A8KXJCIU4sQCfQroC > k0r75fKUoI5Z3UiE0upzDc8= > =X4SS > -----END PGP SIGNATURE-----