I am studying the ruby object model and have some questions. I understand the idea that an object only stores instance variables, and methods are stored in the class, which an o
Here's my shot at one.
In Ruby, classes are objects. Usually they have class Class
. For example, let's consider the class Foo
.
class Foo
end
Doubtless you've seen this before, and it's not terribly exciting. But we could also have defined Foo
this way:
Foo = Class.new
Just as you'd create a new Foo
by calling Foo.new
, you can create a new Class
by calling Class.new
. Then you give that class the name Foo
by assigning it, just like any other variable. That's all there is to it.