tags:

views:

112

answers:

3

When working in interactive python, I tend to rely on the builtin help() function to tell me what something expects and/or returns, and print out any documentation that might help me. Is there a ruby equivalent to this function?

EDIT I'm looking for something I could use in irb. For example in interactive python I could type

>>> help(1)

which would then print

Help on int object:

class int(object) | int(x[, base]) -> integer | |

Convert a string or number to an integer, if possible. A ...

+3  A: 

Try using ri from the command line.

It takes a class name, method, or module as an argument, and gives you appropriate documentation. Many popular gems come with this form of documentation, as well, so it should typically work even beyond the scope of core Ruby modules.

Matchu
That's cool. But this is only available from the command line, correct? I'm wondering what I could use if I were in irb and I want to get help on a specific variable.
mozillalives
+1  A: 

It's definitely a poor cousin to ipython's help (and one of the main features I miss after moving to ruby), but you can also use ri from within irb. I'd recommend the wirble gem as an easy way to set this up.

Peter
ok, I think this will work. I can get the doc for the class with"Object.ri variable.class" and I can get the method doc with "Object.ri variable.class.to_s + ".method". Thanks
mozillalives
+1  A: 

There's supposed to be irb_help. But like mentioned in that post, it's broken in my ruby install as well.

Mark