From: dblack@... Date: 2007-08-02T20:43:23+09:00 Subject: Re: Private methods not so private? --1926193751-1278936812-1186055005=:5495 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-1278936812-1186055005=:5495" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-1278936812-1186055005=:5495 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Thu, 2 Aug 2007, "J=F8rgen P. Tjern=F8" wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Daniel Berger wrote: >> [ .. snip .. ] >> The advantage of allowing send to access private methods is that it >> allows you to test private methods. :) > Isn't that a Bad Practice (tm)? Private methods are mostly meant for the > internals of a class, and a test should really only test how the class > interacts with the rest of the world - right? (i.e. public methods) No; you definitely want to test your private methods too. First of all, if you're writing a class, you need to test its internals; nothing should be a "black box" for the tests. Second, private methods are actually available to the world, even without send. They just have to be called the right way: puts "Hi" class C attr_accessor :x end C.class_eval { define_method "y" } puts, attr_accessor, and define_method are all private, but you'd certainly want to test them if you had written them. David --=20 * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com) --1926193751-1278936812-1186055005=:5495-- --1926193751-1278936812-1186055005=:5495--