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

  • SEARCH
  • Home
  • 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 979467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:13:23+00:00 2026-05-16T04:13:23+00:00

I am creating non-namespaced classes dynamically. I have seen an example where this creation

  • 0

I am creating non-namespaced classes dynamically.

I have seen an example where this creation is done within the Object class:

class Object

  for elem in ARRAY
    sub_class = Object.const_set(elem.to_s.camelize, Class.new(SuperClass))

    sub_class.class_eval do
      def initialize(*args, &block)
        ...
        super *args, &block
      end
    end
  end

end

My Questions:

  • Would you also evaluate this within the context of Object?
  • Where is the difference from creating classes in global namespace?
  • Any advantages or disadvantages?
  • 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-16T04:13:24+00:00Added an answer on May 16, 2026 at 4:13 am

    Interesting. Upon some experimentation, calling SomeConstant.const_set from different contexts doesn’t make any difference, so calling it inside the class Object block is the same as defining it in the toplevel namespace.

    Furthermore: everything in the global namespace is implicitely defined in the Object class, so it is actually redundant. The only advantage I can see [over defining it in a different class, or in the Kernel module] is that the constant will be available to all classes, and the lookup chain will look at the Object class before the Kernel module.

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

Sidebar

Related Questions

Should I feel wary about creating clojure keywords which have non-existent namespaces? An example
Creating a class at runtime is done as follows: klass = Class.new superclass, &block
I have to related tables like in the example script below: -- Creating table
I have a school project in which I am creating a Non Relational Document
I got trouble in creating special instance of member template function of non-template class.
I am creating a texteditor in c++[non gui] , So far i have ended
What is a good way of creating non-blocking methods in Scala? One way I
I'm creating a non-intrusive popup window to notify the user when processing a time-consuming
I am creating a non-deterministic orchestration to handle convoys. I know I am setting
I was trying to add some non-production test code by creating a 3rd partial

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.