What is Ruby's analog to Python Metaclasses?

Posted by Sean Copenhaver on Stack Overflow See other posts from Stack Overflow or by Sean Copenhaver
Published on 2010-04-20T14:39:53Z Indexed on 2010/04/20 22:33 UTC
Read the original article Hit count: 371

Python has the idea of metaclasses that, if I understand correctly, allow you to modify an object of a class at the moment of construction. You are not modifying the class, but instead the object that is to be created then initialized.

Python (at least as of 3.0 I believe) also has the idea of class decorators. Again if I understand correctly, class decorators allow the modifying of the class definition at the moment it is being declared.

Now I believe there is an equivalent feature or features to the class decorator in Ruby, but I'm currently unaware of something equivalent to metaclasses. I'm sure you can easily pump any Ruby object through some functions and do what you will to it, but is there a feature in the language that sets that up like metaclasses do?

So again, Does Ruby have something similar to Python's metaclasses?

Edit I was off on the metaclasses for Python. A metaclass and a class decorator do very similar things it appears. They both modify the class when it is defined but in different manners. Hopefully a Python guru will come in and explain better on these features in Python.

But a class or the parent of a class can implement a __new__(cls[,..]) function that does customize the construction of the object before it is initialized with __init__(self[,..]).

© Stack Overflow or respective owner

Related posts about ruby

Related posts about python