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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:05:44+00:00 2026-05-28T16:05:44+00:00

I am just starting Ruby and learning the concept of modules. I understand that

  • 0

I am just starting Ruby and learning the concept of modules. I understand that one use of modules is to better organize your code and avoid name clashes. Let’s say I have bunch of modules like this (I haven’t included the implementation as that’s not important)
:

module Dropbox

  class Base

    def initialize(a_user)
    end

  end  

  class Event < Base

    def newFile?
    end

    def newImage?
    end

  end

  class Action < Base

    def saveFile(params)
    end

  end

end

and another module:

module CustomURL

  class Base

    def initialize(a_user, a_url, a_method, some_args, a_regex)
    end

  end

  class Event < Base

    def initialize(a_user, a_url, a_method, some_args, a_regex)
    end

    def change?
    end

  end

  class Action < Base

    def send_request(params)
    end

  end

end

I am going to have a bunch of these modules (10+, for gmail, hotmail, etc…). What I am trying to figure out is, is this the right way to organize my code?

Basically, I am using module to represent a “service” and all services will have a common interface class (base for initializing, action for list of actions and event for monitoring).

  • 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-28T16:05:45+00:00Added an answer on May 28, 2026 at 4:05 pm

    You are defining families of related or dependent classes here. Your usage of modules as namespaces for these families is correct.

    Also with this approach it would be easy to build abstract factory for your classes if they had compatible interface. But as far as I see this is not the case for current classes design: for example Dropbox::Event and CustomURL::Event have completely different public methods.

    You can reevaluate design of your classes and see if it is possible for them to have uniform interface so that you can use polymorphism and extract something like BaseEvent and BaseAction so that all Events and Actions will derive from these base classes.

    Update: As far as you define services, it might be useful to define top-level module like Service and put all your classes inside this module. It will improve modularity of your system. If in the future you would refactor out some base classes for your modules services, you can put them in the top-level namespace. Then your objects will have readable names like these:

    Service::Dropbox::Event
    Service::Dropbox::Action
    Service::CustomURL::Event
    Service::CustomURL::Action
    Service::BaseEvent
    Service::BaseAction
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just starting out in learning Ruby and I've written a program that generates
I'm just starting out using Ruby and I've written a bit of code to
I'm just starting out with Ruby/Rails and am wondering what Rails developers use to
I've done some Python but have just now starting to use Ruby I could
Just starting to use Ruby on Rails to see what its like. I have
I'm just starting to use constants in Ruby. I have module Constants C1 =
I'm a Delphi, Ruby, and Javascript programmer that is finally learning C - starting
I am just starting with Ruby on Rails, because I was told that it
I'm learning the basics of Ruby (just starting out), and I came across the
I'm just starting out with rails and I'm practicing the basic ruby commands, one

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.