在控制台中,以任何方式获取某种方法的信息?

Num*_*ers 1 ruby console gem command-line

假设我使用了宝石csv.

通过控制台中的以下内容,我获得了所有实例方法的列表:

require "csv"
csv = CSV.open(FILE_NAME, "a+")
csv.methods
Run Code Online (Sandbox Code Playgroud)

我现在在列表中找到的一种方法是例如first.

我可以从命令行获取有关此方法的信息吗?(是的,我知道我可以谷歌搜索文档.)

Ste*_*fan 5

Pry(IRB替代方案)支持文档浏览:

$ pry
[1] pry(main)> require 'csv'
#=> true

[2] pry(main)> csv = CSV.new('')
#=> <#CSV io_type:StringIO encoding:UTF-8 lineno:0 col_sep:"," row_sep:"\n" quote_char:"\"">

[3] pry(main)> show-doc csv.first

From: enum.c (C Method):
Owner: Enumerable
Visibility: public
Signature: first(*arg1)
Number of lines: 8

Returns the first element, or the first n elements, of the enumerable.
If the enumerable is empty, the first form returns nil, and the
second form returns an empty array.

  %w[foo bar baz].first     #=> "foo"
  %w[foo bar baz].first(2)  #=> ["foo", "bar"]
  %w[foo bar baz].first(10) #=> ["foo", "bar", "baz"]
  [].first                  #=> nil
Run Code Online (Sandbox Code Playgroud)

根据文档,您不必事先生成文档:

撬文件系统不依赖于预先生成的rdocri,而不是它抓住直接对需求的方法,上述评论.这样可以加快文档检索速度,并允许Pry系统检索无法获取的方法的文档rdoc.