[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

class#methods how ?

Simon Strandgaard

11/10/2003 11:44:00 AM

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>
3 Answers

ts

11/10/2003 11:52:00 AM

0

>>>>> "S" == Simon Strandgaard <qj5nd7l02@sneakemail.com> writes:

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

p instance_methods(false)

S> end
S> end


--

Guy Decoux

Simon Strandgaard

11/10/2003 11:53:00 AM

0

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 ?


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>

Simon Strandgaard

11/10/2003 12:17:00 PM

0

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

>>>>>> "S" == Simon Strandgaard <qj5nd7l02@sneakemail.com> writes:
>
> 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'.

--
Simon Strandgaard