"ri”って何だ?

rubyの「ri」は、perlにおけるperldocのような存在(らしい…)。
CentOS5にデフォルトではinstallされていなかったのでinstallしてみた。

# yum install ri
Loading "installonlyn" plugin
Loading "fastestmirror" plugin
Setting up Install Process
Setting up repositories
base                      100% |=========================| 1.1 kB    00:00
updates                   100% |=========================|  951 B    00:00
addons                    100% |=========================|  951 B    00:00
extras                    100% |=========================| 1.1 kB    00:00
Loading mirror speeds from cached hostfile
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for ruby-ri to pack into transaction set.
ruby-ri-1.8.5-5.el5.i386. 100% |=========================| 1.0 MB    00:04
---> Package ruby-ri.i386 0:1.8.5-5.el5 set to be updated
--> Running transaction check
--> Processing Dependency: ruby-rdoc = 1.8.5-5.el5 for package: ruby-ri
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for ruby-rdoc to pack into transaction set.
ruby-rdoc-1.8.5-5.el5.i38 100% |=========================|  25 kB    00:00
---> Package ruby-rdoc.i386 0:1.8.5-5.el5 set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 ruby-ri                 i386       1.8.5-5.el5      base              1.7 M
Installing for dependencies:
 ruby-rdoc               i386       1.8.5-5.el5      base              135 k

Transaction Summary
=============================================================================
Install      2 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 1.8 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): ruby-ri-1.8.5-5.el 100% |=========================| 1.7 MB    00:06
(2/2): ruby-rdoc-1.8.5-5. 100% |=========================| 135 kB    00:00
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: ruby-rdoc                    ######################### [1/2]
  Installing: ruby-ri                      ######################### [2/2]

Installed: ruby-ri.i386 0:1.8.5-5.el5
Dependency Installed: ruby-rdoc.i386 0:1.8.5-5.el5
Complete!
#

使用例(1)

  • 失敗
# ri print

More than one method matched your request. You can refine
your search by asking for information on one of:

     CGI::print, CGI#print, Zlib::GzipWriter#printf,
     Zlib::GzipWriter#print, Kernel#sprintf, Kernel#printf,
     Kernel#print, MatchData#pretty_print, Hash#pretty_print_cycle,
     Hash#pretty_print, File::Stat#pretty_print,
     Racc::Parser#racc_print_stacks, Racc::Parser#racc_print_states,
     RI::TextFormatter#bold_print, RI::TextFormatter#raw_print_line,
     RI::HtmlFormatter#bold_print, RI::OverstrikeFormatter#bold_print,
     RI::AttributeFormatter#bold_print, RI::AnsiFormatter#bold_print,
     DEBUGGER__::Context#debug_print_help, Range#pretty_print,
     Struct#pretty_print_cycle, Struct#pretty_print,
     Array#pretty_print_cycle, Array#pretty_print,
     PP::ObjectMixin#pretty_print_cycle, PP::ObjectMixin#pretty_print,
     PP::ObjectMixin#pretty_print_instance_variables,
     PP::ObjectMixin#pretty_print_inspect, RDoc::Stats#print, IO#printf,
     IO#print, Net::WriteAdapter#printf, Net::WriteAdapter#print,
     Net::Telnet#print, Net::HTTP::get_print, StringIO#printf,
     StringIO#print

使用例(2)

  • 成功
  • どのパッケージ(?)に属しているか明示的に記述しないとだめらしい…。
# ri Kernel#print
----------------------------------------------------------- Kernel#print
     print(obj, ...)    => nil
------------------------------------------------------------------------
     Prints each object in turn to +$stdout+. If the output field
     separator (+$,+) is not +nil+, its contents will appear between
     each field. If the output record separator (+$\+) is not +nil+, it
     will be appended to the output. If no arguments are given, prints
     +$_+. Objects that aren't strings will be converted by calling
     their +to_s+ method.

        print "cat", [1,2,3], 99, "\n"
        $, = ", "
        $\ = "\n"
        print "cat", [1,2,3], 99

     _produces:_

        cat12399
        cat, 1, 2, 3, 99

#