2013-03-29 114 views
17

的Ruby文檔有沒有發現我的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 

我應該怎麼做才能使文檔出現?

回答

26

如果您使用RVM來管理你的Ruby安裝,你可以這樣做:

rvm docs generate 

如果沒有,嘗試這樣做:

gem install rdoc-data 
rdoc-data --install 

然後再次嘗試ri命令。

+0

沒有,我使用的紅寶石從ArchLinux的包管理 – Kokizzu

+0

好吧,我會嘗試第二個:3感謝 – Kokizzu

+0

是的,它的工作原理:3感謝 – Kokizzu

3

您在評論中提到您正在使用archlinux的包管理器中的Ruby包。你需要ri什麼是安裝ruby-docs包:

$ pacman -S ruby-docs 

我猜他們分開了包,這樣的人不想要的文檔誰可以節省磁盤使用情況。

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。試着要求這些,你可能會得到他們的文檔。

+0

啊,是的,都是。和#在pry中不工作,但都在正常的rimamamand線上工作 – Kokizzu

11

隨着撬,最好安裝pry-doc寶石,然後使用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如果你喜歡。