Ruby的`BasicObject.new`没有文档吗?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ruby的`BasicObject.new`没有文档吗?相关的知识,希望对你有一定的参考价值。

我想阅读new方法的Ruby文档,如下所示:

class Dog
end

fido = Dog.new("Fido")

但是通过Ruby文档进行追踪会引导我进入this

new()

没有记录

我是在寻找错误的地方,还是实际上没有记录的最普遍的方法之一?

答案

看看Dog.new("Fido"),我相信你正在寻找Class#new,而不是BasicObject#new。因为你的Dog类是Class的一个例子。

class Dog
    #code
end
Dog.instance_of? Class # => true

更多例子:

Foo = Class.new # Class::new is called
Foo.instance_of? Class # => true
foo = Foo.new # Class#new is called
foo.instance_of? Foo   # => true

以上是关于Ruby的`BasicObject.new`没有文档吗?的主要内容,如果未能解决你的问题,请参考以下文章

Ruby on Rails 中文本区域的最大长度

使用 Ruby on Rails 在文本区域中保留换行符

Ckeditor无法保存textarea值(Ruby on Rails)

Linux系统下Ruby安装

将不间断空格转换为 Ruby 中的空格

#map_find 在 Ruby 中?