From: Trans Date: 2008-04-25T10:21:15+09:00 Subject: Re: Is there any nomenclature for private methods? On Apr 24, 7:49 pm, Iņaki Baz Castillo wrote: > Hi, I don't like the way of declaring publi and private methods since it's not > really clear. AFAIK there are you ways: > > 1) > class C > def public_1 > end > > def public_2 > end > > private: > def private_1 > end > > public: > def public_3 > end > > or: > > 2) > class C > def public_1 > end > > def public_2 > end > > def private_1 > end > > def public_3 > > private :private_1 > end One way is do it immediately after the method. E.g. def private_1 end private :private_1 def public_3 end I've seen other coders use the declarations before every single method regardless public def public_2 end private def private_1 end public def public_3 end I agree that these declarations are one of the "sore-eyes" of Ruby, but what else can be done? Matz has always seemed against allowing: private def foo() end In many ways it's really not important though. A more Ruby-esque way in my opinion is to just make them all public and document them appropriately. There is the exception of method_missing's behavior however. > I prefer 2) but until the end of class it's not easy to know if a method is > public or private/protected. So i'm thinking about use a special nomenclature > for private methods, for example: > > def _private_1 > > Is there any "standar" for this? I've seen lost of ethods called "__xxxx__" > or "_xxxxx" but not sure the reason of that name. An initial underscore or double underscore basically indicates "special/avoid overwrite" --meaning it's meant to reduce the likelihood that someone else might define a method/attribute of the same name. The most common occurrence is __send__. T.