ruby picture

RCR 197: ri should be accesible thru irb

Submitted by gga (Mon Jan 19 08:01:19 UTC 2004)

Abstract

Add a help() function to irb that would invoke ri on any module.

Problem

Using irb, it is common for newbies to need help checking syntax or verifying methods of classes. Even for those experienced in the language, it is sometimes necessary to consult docs of a module you are unfamiliar with.

Python's interactive console allows accessing its docs for any built-in class using help(class). In python, it is even possible to load a module and then do help(module) to obtain information about it.

It is also possible to use: help() and enter help mode in the python console. This allows you to basically find help about python's built in commands, list all modules available in all paths of $: and a list of topics about the language.

Proposal

I propose a similar method is used in irb to access ri docs as a start. As a second step, this should be complemented to provide full online help of all ruby commands.

Analysis

Ideally, this should be possible to do even on modules that have NOT had ri run on them.

Implementation

In irb, add a Kernel::help() function that would invoke ri on the given string (assuming a module/class or class#method). If module is found in $: but rdoc has not been run on it to get ri, it should perhaps run rdoc on it automatically?
ruby picture
Comments Current voting

I don't know how necessary it is to integrate ri with irb. It is fairly easy to run ri from another console. I may like the idea of ri automatically running rdoc on classes/modules found in $:. The problem is you wouldn't want run rdoc every time for classes that don't have rdoc documentation. So you'd have to keep a list of classes/modules you've already searched. And when the rdocs do get added to that class, how would you know to update? If someone can think of a good way to do this, I'm all for it. I'm not yet convinced it can be done well, though. -- Zachary Landau


for a simplish implementation without rdoc autorun. Contextual help is a good match with the reflective capabilities of Ruby, in my opinion. Having an agreement on the preferred way of accessing documentation from within the language would help with dynamically created objects too (anonymous classes, lambdas, singleton methods, ?) -- Ilmari Heikkinen


Strongly opposed 0
Opposed 0
Neutral 1
In favor 5
Strongly advocate 14
ruby picture
If you have registered at RCRchive, you may now sign in below. If you have not registered, you may sign up for a username and password. Registering enables you to submit new RCRs, and vote and leave comments on existing RCRs.
Your username:
Your password:

ruby picture

Powered by .