Is Class declaration an eyewash in ruby? Is everything really object oriented?

不问归期 提交于 2019-12-02 00:58:42

Yes, Ruby classes are objects:

>> String.is_a? Object
=> true
>> String.methods.count
=> 131
>> Fixnum.methods.count
=> 128

Yes, classes in Ruby are instances of class Class. In fact, you can create the same class just with:

Person = Class.new do
  define_method :name do
    puts 'Dave'
  end
end

Then, you can just type Person.new.name and it will work exactly as your class.

Checking that Person is an instance of class Class is as easy as typing in your repl Person.class and you get Class in return.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!