Ruby is a pure Object-Oriented programming language. Everything in Ruby is objects, even classes. Amazing? Let's see why:
irb> 'hello'.class
=> String
irb> String.class
=> Class
irb> Array.class
=> Class
irb> Class.class
=> Class
=> String
irb> String.class
=> Class
irb> Array.class
=> Class
irb> Class.class
=> Class
See even further:
irb> Class.superclass
=> Module
irb> Module.superclass
=> Object
irb> Object.superclass
=> nil
=> Module
irb> Module.superclass
=> Object
irb> Object.superclass
=> nil
irb> Module.class
=> Class
irb> Object.class
=> Class
=> Class
irb> Object.class
=> Class
So all classes are objects of class "Class". String, Array,.. are instances of class "Class".
Module and Object are super classes of "Class" but also instances of "Class"!!!
No comments:
Post a Comment