Is everything an object in ruby?

前端 未结 6 1310
迷失自我
迷失自我 2020-12-10 12:03

Is everything in ruby an object? Does this include Fixnums?

6条回答
  •  借酒劲吻你
    2020-12-10 12:47

    Yes. Fixnum is a class, which inherits from Integer, which inherits from Numeric, which finally inherits from Object.

    Or, why don't you just ask it? :)

    1.is_a? Object # => true
    1.class # => Fixnum
    Fixnum.is_a? Object # => true
    

    Reading the Ruby info and documentation on the website is a good idea too.

提交回复
热议问题