如果我像这样使用Prime类:
Prime.new
我会收到下一条消息:
Prime::new is obsolete. use Prime::instance or class methods of Prime.
我tryied finding这个类文档,但不能。
答案 0 :(得分:4)
不幸的是,似乎尚未在ruby-doc.org上发布。但你现在可以看看at the commented source code;它包括用法示例。
答案 1 :(得分:2)
您应该通过ri
:
$ ri Prime
= Prime < Object
------------------------------------------------------------------------------
= Includes:
Enumerable (from ruby core)
(from ruby core)
------------------------------------------------------------------------------
The set of all prime numbers.
== Example
Prime.each(100) do |prime|
p prime #=> 2, 3, 5, 7, 11, ...., 97
end
== Retrieving the instance
Prime.new is obsolete. Now Prime has the default instance and you can access
it as Prime.instance.
...
还有RubyDoc.info,它有更好的索引: