Does ruby have a similar functions to the Python dir and help functions?

Discussion in 'Ruby' started by py, Mar 23, 2007.

  1. py

    py Guest

    In python during runtime, or in the python shell you can type:

    dir()

    or

    dir(<some_object>)

    and get a list of variables, methods etc that exist for that object.

    Also there is help(<some_object>), or help(<some_object.aMethod>).

    does ruby have similar functions. I know that you can use ri....but
    is there a function to call while in the ruby shell?

    thanks
     
    py, Mar 23, 2007
    #1
    1. Advertising

  2. Ruby can tell you the methods: obj.methods (there's also
    #public_methods, #instance_methods, #private_methods, etc.). Ruby can
    tell you the instance variables (#instance_variables).

    Ruby can't tell you the documentation; there's no docstring like there
    is in Python. There are some enhancements to irb available that give
    an ri command from within irb.

    -austin
    --
    Austin Ziegler * * http://www.halostatue.ca/
    * * http://www.halostatue.ca/feed/
    *
     
    Austin Ziegler, Mar 23, 2007
    #2
    1. Advertising

  3. def dir(object)
    object.methods.sort
    end

    That should give you the same effect; as for the help method, ri is
    your only option AFAIK.

    --Jeremy

    On 3/23/07, py <> wrote:
    > In python during runtime, or in the python shell you can type:
    >
    > dir()
    >
    > or
    >
    > dir(<some_object>)
    >
    > and get a list of variables, methods etc that exist for that object.
    >
    > Also there is help(<some_object>), or help(<some_object.aMethod>).
    >
    > does ruby have similar functions. I know that you can use ri....but
    > is there a function to call while in the ruby shell?
    >
    > thanks
    >
    >
    >



    --
    http://www.jeremymcanally.com/

    My free Ruby e-book:
    http://www.humblelittlerubybook.com/book/

    My blogs:
    http://www.mrneighborly.com/
    http://www.rubyinpractice.com/
     
    Jeremy McAnally, Mar 23, 2007
    #3
  4. Le vendredi 23 mars 2007 14:54, Austin Ziegler a =E9crit=A0:
    > Ruby can tell you the methods: obj.methods (there's also
    > #public_methods, #instance_methods, #private_methods, etc.). Ruby can
    > tell you the instance variables (#instance_variables).
    >
    > Ruby can't tell you the documentation; there's no docstring like there
    > is in Python. There are some enhancements to irb available that give
    > an ri command from within irb.
    >
    > -austin


    Actually, irb can give you documentation. For example :

    irb(main):001:0> help Array

    It works like ri.

    =2D-=20
    Olivier Renaud
     
    Olivier Renaud, Mar 23, 2007
    #4
  5. Jonas Pfenniger, Mar 23, 2007
    #5
  6. Re: Does ruby have a similar functions to the Python dir and helpfunctions?

    Austin Ziegler wrote:
    > Ruby can tell you the methods: obj.methods (there's also
    > #public_methods, #instance_methods, #private_methods, etc.). Ruby can
    > tell you the instance variables (#instance_variables).


    you can also use local_variables to get a list of... local variables!

    Daniel
     
    Daniel DeLorme, Mar 24, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UnVkeQ==?=

    Sub Dir, Virtual dir, what do I use?

    =?Utf-8?B?UnVkeQ==?=, Jun 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    434
    =?Utf-8?B?UnVkeQ==?=
    Jun 12, 2005
  2. news reader
    Replies:
    2
    Views:
    781
    Evan Lavelle
    Jul 3, 2007
  3. thomas
    Replies:
    1
    Views:
    545
    James Kanze
    Jul 3, 2009
  4. Weng Tianxiang
    Replies:
    7
    Views:
    1,300
    Paul Uiterlinden
    Sep 11, 2009
  5. Matthew Denner
    Replies:
    1
    Views:
    188
Loading...

Share This Page