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