Does a function like pythons dir() excist for ruby ?

  • Thread starter Asbjørn Reglund Thorsen
  • Start date
A

Asbjørn Reglund Thorsen

I am using interactive Ruby for quick testing my swigged c++ module. In
python i can write down the command dir(), and I will get what`s inside
the module. Is there a similar function for Ruby ?
 
N

nobu.nokada

Hi,

At Wed, 28 Jan 2004 19:54:53 +0900,
Asbjørn Reglund Thorsen said:
I am using interactive Ruby for quick testing my swigged c++ module. In
python i can write down the command dir(), and I will get what`s inside
the module. Is there a similar function for Ruby ?

$ ri instance_methods
------------------------------------------------ Module#instance_methods
mod.instance_methods(include_super=false) => array
------------------------------------------------------------------------
Returns an array containing the names of public instance methods in
the receiver. For a module, these are the public methods; for a
class, they are the instance (not singleton) methods. With no
argument, or with an argument that is +false+, the instance methods
in _mod_ are returned, otherwise the methods in _mod_ and _mod_'s
superclasses are returned.

module A
def method1() end
end
class B
def method2() end
end
class C < B
def method3() end
end

A.instance_methods #=> ["method1"]
B.instance_methods #=> ["method2"]
C.instance_methods #=> ["method3"]
C.instance_methods(true).length #=> 43

A.instance_methods #=> ["method1"]
B.instance_methods #=> ["method2"]
C.instance_methods #=> ["method3"]
C.instance_methods(true).length #=> 43
 

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
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top