要从命令行显示ruby rdoc
文档,只需使用ri
命令,如下所示:
ri String
这个简单的命令将显示ruby String
类的rdoc文档,
ri String
还有这个:
ri String
下面是键入ri String
命令的例子输出:
---------------------------------------------------------- Class: String A +String+ object holds and manipulates an arbitrary sequence of bytes, typically representing characters. String objects may be created using +String::new+ or as literals. Because of aliasing issues, users of strings should be aware of the methods that modify the contents of a +String+ object. Typically, methods with names ending in ``!'' modify their receiver, while those without a ``!'' return a new +String+. However, there are exceptions, such as +String#[]=+. ------------------------------------------------------------------------ Enhance the String class with a XML escaped character version of to_s. ------------------------------------------------------------------------ User defined methods to be added to String. ------------------------------------------------------------------------ Includes: --------- Comparable(<, <=, ==, >, >=, between?), Enumerable(all?, any?, collect, detect, each_cons, each_slice, each_with_index, entries, enum_cons, enum_slice, enum_with_index, find, find_all, grep, group_by, include?, index_by, inject, map, max, member?, min, partition, reject, select, sort, sort_by, sum, to_a, to_set, zip) (more ...)
在命令行中,如果你想从命令行运行简单ruby命令,只需启动irb
,交互式ruby shell,如下所示:
irb
运行该命令后,irb
将按以下的方式提示你:
>>
此时,你可以键入所需的ruby命令,如下所示:
a = 1 + 2
键入命令后,irb
将显示与该命令相关的输出,如下所示:
=> 3