class#methods how ?

S

Simon Strandgaard

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



server> 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
server> 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?", "instance_variable_get", "kind_of?"]
42
server>
 
T

ts

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

p instance_methods(false)

S> end
S> end
 
S

Simon Strandgaard

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 ?


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

--
Simon Strandgaard


server> 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
server> 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
server>
 
S

Simon Strandgaard

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

p instance_methods(false)

S> end
S> end

Even better, Thanks

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top