Skip to content

Daily Archives: August 26th, 2008

Class.new and .inherited()

In Ruby, the typical way to define a class is using the class keyword:

class Foo # …
end

The class keyword, however, is effectively just syntax sugar for the Class constructor:

Foo = Class.new # …
end

Using Class.new is occasionally preferable, e.g. when you want an anonymous class which isn’t assigned to a constant:

@myclass = Class.new […]