简体   繁体   English

Rails 控制台中的 Rails 文档

[英]Rails documentation from rails console

is that a way where i can search the API documentation for a method from the rails console?这是我可以从 Rails 控制台搜索 API 文档的方法吗? Eg the method arguments, returning object, etc例如方法参数、返回对象等

It is not rails console, but it is "ri" in console. 它不是Rails控制台,但在控制台中是“ ri”。 This is what i am looking for. 这就是我想要的。

From irb (it might also work in rails console), you can do从 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);
}

Note you'll need pry and pry-doc installed:请注意,您需要安装 pry 和 pry-doc:

gem install pry
gem install pry-doc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM