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?
views:
62answers:
3As 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.
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.
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.