2017-08-16 34 views
3

我常常忘記新的關鍵字參數的語法,當我想用​​雙splats等來獲取額外的參數時。在線Ruby文檔有文章,例如http://ruby-doc.org/core-2.1.0/doc/syntax/methods_rdoc.htmlhttp://ruby-doc.org/core-2.0.0/doc/syntax/calling_methods_rdoc.html,但是我怎麼能通過ri訪問這個信息?ri中記錄的關鍵字方法參數在哪裏?

或者是ri(正如交互模式的問題「輸入您想要查找的方法名稱」所暗示的那樣)唯一可以找到的東西?

任何幫助或見解將不勝感激。

+2

你是第一臺紅寶石DEV(據我所知),使用'ri' :) –

+0

你是什麼意思你忘記語法?這[SO帖子](https://stackoverflow.com/a/20634180/1978251)有一個很好的解釋的參數順序(也許只是書籤) – engineersmnky

+0

@SergioTulentsev我是最相反的人,我知道所以這不是驚喜! :) – iain

回答

3

您可以通過訪問靜態頁面:

$ ri ruby:syntax/methods 

輸出:

= Methods 

Methods implement the functionality of your program. Here is a simple method 
definition: 

    def one_plus_one 
    1 + 1 
    end 

A method definition consists of the def keyword, a method name, the body of 
the method, return value and the end keyword. When called the method will 
execute the body of the method. This method returns 2. 

This section only covers defining methods. See also the {syntax documentation 
on calling methods}[rdoc-ref:syntax/calling_methods.rdoc]. 

[...] 
+2

啊! 'ri ruby​​:syntax'也帶來了一種菜單頁面,以防我忘記'methods'部分(我會忘記:)。非常好,謝謝。 – iain

+0

謝謝你。我一直在瀏覽各種ri/rdoc文檔/ tutorial/help-pages,我不認爲我曾經在任何地方看過這個(即使用'ruby:'前綴)。 – doubleDown

+2

@doubleDown前綴選擇一個通常是寶石的rdoc數據存儲。 ['RDoc :: Store#source']的文檔(http://ruby-doc.org/stdlib-2.4.1/libdoc/rdoc/rdoc/RDoc/Store.html#method-i-source)提到它也可以是「家」,「網站」和「紅寶石」。 – Stefan