【问题标题】:Rails documentation from rails consoleRails 控制台中的 Rails 文档
【发布时间】:2016-07-08 04:10:02
【问题描述】:

这是我可以从 Rails 控制台搜索 API 文档以查找方法的一种方式吗?例如。方法参数、返回对象等

【问题讨论】:

  • 没有这种动物。但是,您可以使用 rdoc 生成 Rails 文档的本地副本,您可以通过浏览器浏览/搜索。
  • 是的。 ri 是我要找的那个。它不是 Rails 控制台。
  • 令人惊讶的是,这么多年过去了,还没有人做出来。 (在控制台中工作)

标签: ruby-on-rails rails-console


【解决方案1】:

它不是rails控制台,而是控制台中的“ri”。这就是我要找的。​​p>

【讨论】:

    【解决方案2】:

    从irb(它也可能在rails控制台中工作),你可以这样做

    require 'pry'
    pry
    require 'pry-doc'
    ? File.link # Shows documentation for File.link method, replace 
    # with whatever method you want
    
    From: file.c (C Method):
    Owner: #<Class:File>
    Visibility: public
    Signature: link(arg1, arg2)
    Number of lines: 20
    
    Creates a new name for an existing file using a hard link. Will not
    overwrite new_name if it already exists (raising a subclass
    of SystemCallError). Not available on all platforms.
    
       File.link("testfile", ".testfile")   #=> 0
       IO.readlines(".testfile")[0]         #=> "This is line one\n"
    
    static VALUE
    rb_file_s_link(VALUE klass, VALUE from, VALUE to)
    {
        FilePathValue(from);
        FilePathValue(to);
        from = rb_str_encode_ospath(from);
        to = rb_str_encode_ospath(to);
    
        if (link(StringValueCStr(from), StringValueCStr(to)) < 0) {
        sys_fail2(from, to);
        }
        return INT2FIX(0);
    }
    

    请注意,您需要安装 pry 和 pry-doc:

    gem install pry
    gem install pry-doc
    

    【讨论】:

      猜你喜欢
      • 2011-05-11
      • 1970-01-01
      • 2016-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-09
      • 2015-12-21
      相关资源
      最近更新 更多