Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 747149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:10:19+00:00 2026-05-14T14:10:19+00:00

Python has the idea of metaclasses that, if I understand correctly, allow you to

  • 0

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[,..]).

Edit This question is mostly for discussion and learning about how the two languages compare in these features. I’m familiar with Python but not Ruby and was curious. Hopefully anyone else who has the same question about the two languages will find this post helpful and enlightening.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:10:20+00:00Added an answer on May 14, 2026 at 2:10 pm

    Ruby doesn’t have metaclasses. There are some constructs in Ruby which some people sometimes wrongly call metaclasses but they aren’t (which is a source of endless confusion).

    However, there’s a lot of ways to achieve the same results in Ruby that you would do with metaclasses. But without telling us what exactly you want to do, there’s no telling what those mechanisms might be.

    In short:

    • Ruby doesn’t have metaclasses
    • Ruby doesn’t have any one construct that corresponds to Python’s metaclasses
    • Everything that Python can do with metaclasses can also be done in Ruby
    • But there is no single construct, you will use different constructs depending on what exactly you want to do
    • Any one of those constructs probably has other features as well that do not correspond to metaclasses (although they probably correspond to something else in Python)
    • While you can do anything in Ruby that you can do with metaclasses in Python, it might not necessarily be straightforward
    • Although often there will be a more Rubyish solution that is elegant
    • Last but not least: while you can do anything in Ruby that you can do with metaclasses in Python, doing it might not necessarily be The Ruby Way

    So, what are metaclasses exactly? Well, they are classes of classes. So, let’s take a step back: what are classes exactly?

    Classes …

    • are factories for objects
    • define the behavior of objects
    • define on a metaphysical level what it means to be an instance of the class

    For example, the Array class produces array objects, defines the behavior of arrays and defines what “array-ness” means.

    Back to metaclasses.

    Metaclasses …

    • are factories for classes
    • define the behavior of classes
    • define on a metaphysical level what it means to be a class

    In Ruby, those three responsibilities are split across three different places:

    • the Class class creates classes and defines a little bit of the behavior
    • the individual class’s eigenclass defines a little bit of the behavior of the class
    • the concept of “classness” is hardwired into the interpreter, which also implements the bulk of the behavior (for example, you cannot inherit from Class to create a new kind of class that looks up methods differently, or something like that – the method lookup algorithm is hardwired into the interpreter)

    So, those three things together play the role of metaclasses, but neither one of those is a metaclass (each one only implements a small part of what a metaclass does), nor is the sum of those the metaclass (because they do much more than that).

    Unfortunately, some people call eigenclasses of classes metaclasses. (Until recently, I was one of those misguided souls, until I finally saw the light.) Other people call all eigenclasses metaclasses. (Unfortunately, one of those people is the author of one the most popular tutorials on Ruby metaprogramming and the Ruby object model.) Some popular libraries add a metaclass method to Object that returns the object’s eigenclass (e.g. ActiveSupport, Facets, metaid). Some people call all virtual classes (i.e. eigenclasses and include classes) metaclasses. Some people call Class the metaclass. Even within the Ruby source code itself, the word “metaclass” is used to refer to things that are not metaclasses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that python has a len() function that is used to determine the
If you are relying on an implementation of Python that has a Global Interpreter
Almost every Python web framework has a simple server that runs a wsgi application
I have a python script that has to launch a shell command for every
Python has this wonderful way of handling string substitutions using dictionaries: >>> 'The %(site)s
Python's IDLE has 'Check Module' (Alt-X) to check the syntax which can be called
Has anyone seen anything in Tix work under python 3.0? I've tried to work
How to check with python if a path has the sticky bit set?
I'd like to have a python program alert me when it has completed its
My Google-fu has failed me. In Python, are the following two tests for equality

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.