Ruby equivalent of Python help ()?

When working in interactive Python, I tend to rely on the built-in help() function to tell me that something is expecting and / or returning, and print any documentation that might help me. Is Ruby equivalent to this function?

I am looking for something that I could use in irb. For example, in interactive Python, I can enter:

 >>> help(1) 

which will then print

 Help on int object: class int(object) | int(x[, base]) -> integer | | Convert a string or number to an integer, if possible. A ... 
+18
python ruby
Jan 05
source share
5 answers

This is definitely a bad cousin to help iPython and one of the main functions that I miss after switching to Ruby, but you can also use ri from irb . I would recommend the pearl as an easy way to fix this.

+5
Jan 05 '10 at 23:07
source share

Try using ri from the command line.

The argument requires a name, method, or module of the class, as well as related documentation. Many popular gems also come with this form of documentation, so they usually work even outside the core Ruby modules.

+5
Jan 05 '10 at 22:48
source share

Now at the end of 2014 and here are two ways to get the similarities of Python help() * if you have Ruby Docs :

  • From within irb you can call the help method with a string describing what you are looking for.

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

  • On 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 as good as Python, but still better than nothing

+3
Sep 04 '14 at 17:16
source share

It is assumed that irb_help . But, as mentioned in this post, it also crashed into my ruby ​​mount.

0
Jan 05 '10 at 23:17
source share

For quick access to the ruby ​​documentation shell, just type ri and then the method you want to learn more (from your shell).

For example:

ri puts

This should be running in your shell and not in irb (interactive ruby ​​environment)

If you are in an irb environment, then another way is to simply type in the help, followed by the method that you want to learn more about:

 help puts 

However, this assumes that you have set up the Ruby environment correctly so that (help) works correctly in irb. Usually I just open another shell and just use ri directly for quick access when I doubt some method or arguments for a method.

0
Nov 08 '15 at 19:21
source share



All Articles