20

有没有办法找出我的ri命令的哪一部分没有显示 Ruby 的文档:

 $ ruby --version
 ruby 1.9.3p392 (2013-02-22 revision 39386) [i686-linux]

 $ ri --version
 ri 3.12.2     

 $ ri String
 Nothing known about String

当我使用撬时:

 $ pry --version
 Pry version 0.9.12 on Ruby 1.9.3

 $ pry 
 [1] pry(main)> ri String
 # shows String documentation
 [2] pry(main)> ri String.split
 error: 'String.split' not found
 [3] pry(main)> ri String.strip
 String.strip not found, maybe you meant:
 String#strip_heredoc

我应该怎么做才能使文档出现?

4

4 回答 4

30

如果您使用RVM管理您的 Ruby 安装,您可以这样做:

rvm docs generate

如果没有,请尝试这样做:

gem install rdoc-data
rdoc-data --install

然后再次尝试该ri命令。

于 2013-03-29T04:20:05.107 回答
12

使用pry,最好先安装pry-docgem,然后使用show-doc命令:

[17] pry(main)> show-doc String#inspect

From: string.c (C Method):
Owner: String
Visibility: public
Signature: inspect()
Number of lines: 6

Returns a printable version of _str_, surrounded by quote marks,
with special characters escaped.

   str = "hello"
   str[3] = "\b"
   str.inspect       #=> "\"hel\\bo\""
[18] pry(main)> show-doc Array#pop

From: array.c (C Method):
Owner: Array
Visibility: public
Signature: pop(*arg1)
Number of lines: 11

Removes the last element from self and returns it, or
nil if the array is empty.

If a number n is given, returns an array of the last n elements
(or less) just like array.slice!(-n, n) does. See also
Array#push for the opposite effect.

   a = [ "a", "b", "c", "d" ]
   a.pop     #=> "d"
   a.pop(2)  #=> ["b", "c"]
   a         #=> ["a"]
[19] pry(main)> 

注意:如果您愿意,也可以使用?别名。show-doc

于 2013-03-31T21:00:45.723 回答
3

您在评论中提到您正在使用来自 archlinux 的包管理器的 Ruby 包。您需要的ri是安装ruby-docs软件包:

$ pacman -S ruby-docs

我猜他们将软件包分开,以便不想要文档的人可以节省磁盘使用量。

于 2013-03-29T06:02:16.393 回答
2

当我使用撬时:

$ pry --version
Pry version 0.9.12 on Ruby 1.9.3

$ pry 
[1] pry(main)> ri String
# shows String documentation
[2] pry(main)> ri String.split
error: 'String.split' not found
[3] pry(main)> ri String.strip
String.strip not found, maybe you meant:
String#strip_heredoc

我应该怎么做才能使文档出现?

好吧,没有方法String.splitString.strip. 但是,有方法String#splitString#strip. 尝试询问这些,您可能会得到他们的文档。

于 2013-03-29T11:07:07.363 回答