21.4. The ri Utility

The ri is apparently named from “Ruby index” or some such mnemonic. It is a command-line documentation tool, offering information on Ruby classes, methods, modules, and so on. Here is an example:

$ ri each_with_index
--------------------------------------------------------
  enumObj.each_with_index {| obj, i | block }  -> nil
--------------------------------------------------------

  Calls block with two arguments, the item and its index,
  for each item in enumObj.

     hash = Hash.new
     %w(cat dog wombat).each_with_index {|item, index|
       hash[item] = index
     }
     hash   #=> {"dog"=>1, "wombat"=>2, "cat"=>0}

Note that it has a few bugs and quirks. You are encouraged to report these (along with typos and other inaccuracies) if you can find anyone ...

Get The Ruby Way: Solutions and Techniques in Ruby Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.