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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:39:55+00:00 2026-05-26T08:39:55+00:00

So Module can be used in Ruby to provide namespacing in addition to mixins,

  • 0

So Module can be used in Ruby to provide namespacing in addition to mixins, as so:

module SomeNamespace
  class Animal

  end
end

animal = SomeNamespace::Animal.new

But I’ve also seen the following used:

module SomeNamespace
end

class SomeNamespace::Animal

end

animal = SomeNamespace::Animal.new

My question is how they’re different (if they are) and which is more idiomatic Ruby?

  • 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-26T08:39:55+00:00Added an answer on May 26, 2026 at 8:39 am

    The difference lies in nesting.

    In the example below, you can see that the former method using class Foo, can get the outer scope’s constant variables BAR_A without errors.

    Meanwhile, class Baz will bomb with an error of uninitialized constant A::B::Baz::BAR_A. As it doesn’t bring in A::* implicitly, only A::B::*explicitly.

    module A
      BAR_A = 'Bar A!'
      module B
        BAR_B = 'Bar B!'
          class Foo
            p BAR_A
            p BAR_B
          end
      end
    end
    
    class A::B::Baz
      p BAR_A
      p BAR_B
    end
    

    Both behaviors have their place. There’s no real consensus in the community in my opinion as to which is the One True Ruby Way ™. I personally use the former, most of the time.

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

Sidebar

Related Questions

The dis module can be effectively used to disassemble Python methods, functions and classes
Is there a Python module that can be used in the same way as
Can someone suggest a good module in perl which can be used to store
I am looking for a module that can create sitemap in Drupal, but couldn't
The Python pwd module provides access to getpwnam(3) POSIX API, which can be used
Is there an existing python module that can be used to detect which distro
I haven't used Ruby much but I am trying to learn. I found a
In the Ruby Standard Library we have the Singleton class: http://ruby-doc.org/stdlib/libdoc/singleton/rdoc/index.html We can make
For instance, these are defined in the operator module and can be used as
Can anyone recommend a module or other Drupal add-on that can be used to

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.