views:

62

answers:

3

I'm new to Ruby - what tricks can I use to help me find documentation on a object I'm working with? Normally I just do a_var.class or a_var.methods and try to guess what I need or search the web for documentation. Are there other methods or modules that might help?

+1  A: 

As long as you have the documentation installed for your installation of Ruby, you can type help "String" to show the documentation for the String class, for instance. Or you can type help obj.Class to achieve the same effect.

For documentation on instance methods, the syntax is Class#method; and Class::method for class methods. That is to say, help "String#chop" or help "String::new" will bring up the respective documentation.

Mark Rushakoff
I'm getting a weird error when I try this. Any chance you run Ubuntu? Here's what I'm getting NameError: undefined method `execute' for module `IRB::ExtendCommand::Help' from (eval):4:in `instance_method' from (eval):4:in `help' from (irb):1Not sure what's causing this, maybe I'm missing a package.
mozillalives
@mozilla: I haven't come across that error before. You might need to double check that you have the docs generated (try `ri Kernel` at the command line).
Mark Rushakoff
+1  A: 

If you're using Vim there are some great plugins that will pull up the ri documentation in the window as you edit. I use PA_ruby_ri, which maps to ,ri and shows the ri docs for the class or method under the cursor.

Of course, when I need broader information about a class, or a method within the context of a class or module, a quick trip to the 1.9 documentation at ruby-doc.org is hard to beat.

michaelmichael
A: 

To get a useful overview of an object's methods, definitely try method_lister or looksee.

For a handy wrapper around ri in irb, read this post.