Matz,
First, I’m very glad that you answered my mail.
Yukihiro M. [email protected] wrote:
1/ why public, protected, private methods cannot be used for
defining the visibility of class methods in addition to defining the
visibility of instance methods ? Is there a technical reason or a
conceptual reason for this ?
I am not sure what you mean here by “defining the visibility of class
methods in addition to defining the visibility of instance methods”.
Can you elaborate?
Sure. I wrote the following code a few days ago :
class C
def one
puts “One”
end
def self.other_one
puts “Other one”
end
private
def two
puts “Two”
end
def self.other_two
puts “Other two”
end
private_class_method :other_two # added later
end
What I basically expected is that the private method will make the
class method “other_two” private as it makes private the instance method
“two”.
I realized later the usefulness of the private_class_method so I added
the commented line afterwards.
What I’d like if possible is that the private method (and its friend
protected and public) works also for class methods.
If you want to change class method visibility, use singleton class
notation, "class <<
I agree. But the public_class_method and private_class_method does the
job without having to go into the singleton class.
| 2/ why the protected_class_method is missing ?
| The only methods are private_class_method and public_class_method.
We don’t have private_class_methods nor public_class_methods in Ruby.
Are confusing with something else?
Yes. I just mean that there is no method for making a class method
protected like there are ones for making a class method private or
public.
What is missing is a protected_class_method similar as
private_class_method and public_class_method.
| 3/ The naming of these methods are quite confusing. Each time I
read them I understand “give me the private/public class method …”.
The naming is too/very close to private_methods, public_methods, …
| I would prefer something like class_private, class_protected, class_public.
What do you confuse with what? For me, class_private etc. mean nothing.
You have methods like private_methods / private_instance_methods, …
returning the private methods / private instance methods of an
object/class.
private_class_method sounds like return me the private class method of
…
This is a bit confusing.
For my suggestion :
like you have private, protected, public for defining the visibility
of instance methods, you will have class_private, class_protected,
class_public for the visibility of class methods.
The prefix class_ is a hint for indicating that these methods work for
class methods.
Examining your questions before asking something is a tip to get
useful answers.
matz.
It seems that my questions were not clear initially.
I hope that it is now more clear.