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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:18:53+00:00 2026-06-01T13:18:53+00:00

Is this good practice? Storing objects accessed by a constant. There are plenty of

  • 0

Is this good practice? Storing objects accessed by a constant. There are plenty of ways to store objects to be accessed by other classes for processing. Using constants instead as means to store hash objects that point to collections is something I recently started doing besides * @@class_variables. What would be the pro’s / con’s to this if there are any? Not really new to OOP but any insight what would be bad practice would be appreciated.

  #!/usr/bin/env ruby 
  OUTSIDE_STATE = true

  NAMES = {:objects => []}

  module CheckSelf
    module ClassMethods
      def self.inherited(child)
        ::NAMES[:objects] << child
      end

      def select_and_make_calls
        _selected = NAMES[:objects].select {|child|
            child.purpose() 
          }.each {|child|
          # _child = child.new(child)
          child.new(child).call_out
        }
      end    
    end

    module InstanceMethods
      def call_out
        puts "FIRING OFF THE CALLS #{self.class}"
      end
    end

    def self.included(receiver)
      receiver.extend         ClassMethods
      receiver.send :include, InstanceMethods
    end
  end

  class Parent

    def initialize(name)
      @name = name
    end  

    include CheckSelf

    # The inherited class must be defined in the * 
    # Body of the class.
    def self.inherited(child)
      NAMES[:objects] << child
    end

  end

  class ObjectOne < Parent

  def self.purpose
      OUTSIDE_STATE
    end
  end

  class ObjectTwo < Parent
    def self.purpose
      true
    end

  end

  Parent.select_and_make_calls
  • 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-01T13:18:54+00:00Added an answer on June 1, 2026 at 1:18 pm

    I recommend against using constants to store changing data. Using constants not only tells the interpreter that your data won’t change, it also tells other programmers that read your code. If you need somewhere to store data over time, use a @@class_variable, and @instance_variable or a $global instead.

    This is not so much an OOP convention as a ruby convention.

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

Sidebar

Related Questions

Is there any good practice for this? I wish I could solve the problem
I have heard that using static member objects is not a very good practice.
So basically, this is what I have. But is this a good practice? I
Is this legal and/or good practice? #define SOFTWARE_VERSION_NUMBER 7.0v1.1 Want struct to always contain
This is a design question and good practice question. How do you structure your
Sorry if this is a bit random, but is it good practice to give
What is considered good practice for querying entites from a database using a simple
This is more like a good practise question. I want to offer different generic
is this good code? can it be simplified somehow? SELECT u.id,u.title,u.title,u.first,u.last FROM (((tblusers u
Is this good OO Design assuming you want every inheriting class to be a

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.