Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby equivalent to Python's help()?

Tags:

python

ruby

When working in interactive Python, I tend to rely on the built-in 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?

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 ...
like image 599
mozillalives Avatar asked Jan 05 '10 22:01

mozillalives


3 Answers

It's now late 2014 and here's the two ways to get the Python help() *similarity, as long as you have the Ruby Docs installed:

  1. From inside irb, You can call the help method with a string describing what you're looking for.

    Example 1: help 'Array' for the Array class
    Example 2: help 'Array#each' for the Array class each method.

  2. From the command line, outside of irb, you can use the ri program:

    Example 1: ri 'Array' for the Array class
    Example 2: ri 'Array#each' for the Array class each method.

* Not quite as good as Python's, but still better than nothing

like image 75
Freedom_Ben Avatar answered Nov 19 '22 15:11

Freedom_Ben


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.

like image 35
Peter Avatar answered Nov 19 '22 17:11

Peter


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.

like image 5
Matchu Avatar answered Nov 19 '22 16:11

Matchu