Inside the Object Model

Where you learn surprising facts about objects, classes, and constants.

Your recent experience with Open Classes (Open Class) hints that there is more to Ruby classes than meets the eye. Much more, actually. Some of the truths about Ruby classes and the object model in general might even come as a bit of a shock when you first uncover them.

There is a lot to learn about the object model, but don’t let all this theory put you off. If you understand the truth about classes and objects, you’ll be well on your way to being a master of metaprogramming. Let’s start with the basics: objects.

What’s in an Object

Imagine running this code:

 class​ MyClass
 def​ my_method
  @v = 1
 end
 end
 
 obj = MyClass.new

Get Metaprogramming Ruby 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.