新手问题 Ruby 文档里的 option 项去哪里看?

mfb777 · 2012年10月06日 · 最后由 congteng 回复于 2012年10月08日 · 2680 次阅读

比如这样的:

foreach(path, options = Hash.new, &block)

怎样知道支持哪些 option?

你用的什么文档?我的文档里没有你描述的这个方法

#1 楼 @jjym 举得例子是在 CSV 标准库里的,链接:http://ruby-doc.org/stdlib-1.9.3/libdoc/csv/rdoc/CSV.html#method-c-foreach

这样的参数形式应该很多见了吧,在 Rails 中更多,比如连接数据库的时候,

ActiveRecord::Base.establish_connection(
  :adapter  => "mysql",
  :host     => "localhost",
  :username => "myuser",
  :password => "mypass",
  :database => "somedatabase"
)

假设有时候不记得 :encoding 怎么拼写了,该去哪里看,类似 :adapter、:host 这样所有可用的选项?

The options parameter can be anything ::new understands. This method also understands an additional :encoding parameter that you can use to specify the Encoding of the data in the file to be read.

你看的不仔细

#3 楼 @jjym 是的,后来我也发现那个介绍了。但是有时候,文档里没有说明的,该去哪里找呢?

#3 楼 @jjym 是的,后来我也发现那个介绍了。但是有时候,文档里没有说明的,该去哪里找呢?

一般都会有类似的告诉你去哪能找到,仔细看就行了

#6 楼 @jjym 那比如 establish_connection 所有可用的选项,在哪里能找到呢?Rails API 里边都是举例,没有全部说明。

google the question

文档找不到,直接看代码,不坑爹

看源码 + 1

需要 登录 后方可回复, 如果你还没有账号请 注册新账号