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 8220781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:39:30+00:00 2026-06-07T13:39:30+00:00

Is it valid and/or acceptable to use a class for namespacing as opposed to

  • 0

Is it valid and/or acceptable to use a class for namespacing as opposed to a module? Maybe it’s just a matter of opinion, but I thought someone might have experience with this that could say definitively whether or not it’s an accepted practice.

Take the following classes for example:

class Parent
end

class Parent::Child1 < Parent
end

class Parent::Child2 < Parent
end

I know the above code works, but it seems weird to use a class instead of a module for the namespace. The reason I want to add the parent class name to the subclass is because I plan on having a lot of subclasses and want to avoid name conflicts. For example:

class Priority
end

class Priority::Low < Priority
end

class Temperature
end

class Temperature::Low < Priority
end

The alternative to this would be to not use namespaces and just use the parent name as part of the subclass name:

class PriorityLow < Priority
end

Is there a best practice for namespacing in Ruby?

Update:

@sawa asked below for some examples. It’s for a Gem that I built called classy_enum which allows users to define classes that are members of an Enum type. Check out the example usage section for a little more background on it. I am cleaning up the code base and it occurred to me that my suggested naming scheme could be improved. So instead of using PriorityLow, you could use Priority::Low (or whatever makes the most sense, but I’m leaning toward the latter)

  • 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-06-07T13:39:33+00:00Added an answer on June 7, 2026 at 1:39 pm

    I don’t have a definitive answer, but it seems worth noting that the Ruby Class class is a subclass of Module, which means to me that a Class is a type of Module, which suggests that it’s probably reasonable to do what you want. I certainly can’t see any reason to avoid it, though I’m curious to see if anyone comes up with any potential downsides.

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

Sidebar

Related Questions

I have a valid reason for wanting to do this, but it's a long
is it valid for a foreign key to be null? i just created a
Possible Duplicates: Valid use of goto for error management in C? Examples of good
Possible Duplicate: #include anywhere For the respective languages, is the following valid (acceptable programming
I'm just getting to know regular expressions, but after doing quite a bit of
Considers me@there valid. Is not a TLD required? try { foreach (var email in
Is it logically valid to do this: child.frame = parent.bounds Let's say I want
Is it valid C to declare a struct and define values enclosed in {}?
I have a valid SAML 2 token from my application IdP: When I try
i get a valid fd object from a caller. How can i find out

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.