Class#methods how?

How do I obtain an Array of methods?
So that I get ‘test1’ and ‘test2’ returned ?

Is it the right class I have installed #debug inside?
Perhaps it should it be Module or Class ?

···


Simon Strandgaard

expand -t2 a.rb
class Object
def self.debug(*args)
p public_methods # how to obtain ?
end
end

class Test
def test1
puts “42”
end
def test2
puts “666”
end
debug :test1
end

Test.new.test1

ruby a.rb
[“to_a”, “instance_eval”, “ancestors”, “const_missing”, “type”, “instance_method”, “protected_methods”, “instance_methods”, “protected_method_defined?”, “extend”, “autoload?”, “eql?”, “instance_variable_set”, “public_class_method”, “const_get”, “is_a?”, “hash”, “to_s”, “class_variables”, “class”, “public_instance_methods”, “tainted?”, “private_methods”, “included_modules”, “untaint”, “private_class_method”, “const_set”, “method”, “id”, “inspect”, “method_defined?”, “clone”, “public_methods”, “protected_instance_methods”, “freeze”, “respond_to?”, “module_eval”, “id”, “<”, “methods”, “<=>”, “==”, “public_method_defined?”, “superclass”, “>”, “===”, “nil?”, “dup”, “instance_variables”, “include?”, “private_instance_methods”, “autoload”, “instance_of?”, “debug”, “const_defined?”, “>=”, “send”, “display”, “name”, “<=”, “class_eval”, “allocate”, “new”, “object_id”, “=~”, “singleton_methods”, “private_method_defined?”, “send”, “equal?”, “taint”, “constants”, “frozen?”, "inst!

ance_variable_get", “kind_of?”]
42

Solved… I wasn’t aware of the #public_instance_methods … now I am.

···

On Mon, 10 Nov 2003 12:44:05 +0100, Simon Strandgaard wrote:

How do I obtain an Array of methods?
So that I get ‘test1’ and ‘test2’ returned ?

Is it the right class I have installed #debug inside?
Perhaps it should it be Module or Class ?


Simon Strandgaard

ruby a.rb
[“dup”, “hash”, “private_methods”, “nil?”, “tainted?”, “class”, “singleton_methods”, “=~”, “send”, “untaint”, “instance_eval”, “extend”, “kind_of?”, “object_id”, “instance_variable_get”, “test1”, “inspect”, “frozen?”, “taint”, “id”, “public_methods”, “to_a”, “equal?”, “respond_to?”, “clone”, “protected_methods”, “display”, “method”, “freeze”, “instance_variable_set”, “type”, “is_a?”, “methods”, “test2”, “send”, “instance_of?”, “==”, “instance_variables”, “id”, “eql?”, “===”, “to_s”]
42
expand -t2 a.rb
class Object
def self.debug(*args)
p public_instance_methods
end
end

class Test
def test1
puts “42”
end
def test2
puts “666”
end
debug :test1
end

Test.new.test1

class Object
def self.debug(*args)
p public_methods # how to obtain ?

   p instance_methods(false)
···

end
end

Guy Decoux

Even better, Thanks

Reading in Pickaxe. The default argument to ‘includeSuper’ has been
changed from ‘false’ into ‘true’.

···

On Mon, 10 Nov 2003 12:52:18 +0100, ts wrote:

class Object
def self.debug(*args)
p public_methods # how to obtain ?

   p instance_methods(false)

end
end


Simon Strandgaard