From: Sean Hermany Date: 2006-06-07T05:06:56+09:00 Subject: Re: Instance methods can't call protected class methods? The problem is that self.call_me is not protected. class Test protected def self.call_me puts "static and protected" end public def invoke_me puts "try to call" Test.call_me # this will _not_ work: self.call_me puts "done" end end t = Test.new print "Output of p Test.protected_methods.sort:\n\n" p Test.protected_methods.sort print "\nOutput of p Test.public_methods.sort:\n\n" p Test.public_methods.sort print "\n" t.invoke_me OUTPUT: ----------------- sean@jefferson:~$ ruby protected_test.rb Output of p Test.protected_methods.sort: [] Output of p Test.public_methods.sort: ["<", "<=", "<=>", "==", "===", "=~", ">", ">=", "__id__", "__send__", "allocate", "ancestors", "autoload", "autoload?", "call_me", "class", "class_eval", "class_variables", "clone", "const_defined?", "const_get", "const_missing", "const_set", "constants", "display", "dup", "eql?", "equal?", "extend", "freeze", "frozen?", "hash", "id", "include?", "included_modules", "inspect", "instance_eval", "instance_method", "instance_methods", "instance_of?", "instance_variable_get", "instance_variable_set", "instance_variables", "is_a?", "kind_of?", "method", "method_defined?", "methods", "module_eval", "name", "new", "nil?", "object_id", "private_class_method", "private_instance_methods", "private_method_defined?", "private_methods", "protected_instance_methods", "protected_method_defined?", "protected_methods", "public_class_method", "public_instance_methods", "public_method_defined?", "public_methods", "respond_to?", "send", "singleton_methods", "superclass", "taint", "tainted?", "to_a", "to_s", "type", "untaint"] try to call static and protected done - Sean Pete wrote: > where's the problem? > > class Test > > protected > def self.call_me > puts "static and protected" > end > > public > def invoke_me > puts "try to call" > Test.call_me > # this will _not_ work: self.call_me > puts "done" > end > > end > > t = Test.new > t.invoke_me > > > > try to call > > static and protected > > done > > > > Sean Hermany schrieb: -- Posted via http://www.ruby-forum.com/.