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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:15:43+00:00 2026-05-19T05:15:43+00:00

Sorry for the lame title: I’m not sure how to sum this one up…

  • 0

Sorry for the lame title: I’m not sure how to sum this one up…

I have a set of classes that are formulas (or formulae if you like), and other set of classes (call them outer classes) that will utilize them.

The formula classes have many attributes (say about 20) and a calculate function. The outer class is a the persistence class and therefore has all the attributes of the formulae class and several more of its own.

In my system, users can configure which formulae class to use, and indeed may chose to calculate using more than one formula for a comparison report for example.

I’m trying to work out how I can transfer attribute values between the inner/formula class and the outer/persistence class without line after line of inner.x = outer.x code.

It seems to me that I can’t use:

class Outer
   include Formula1
end

…because I want the actual Formula class to be configurable.

One idea that springs to mind is I could have an array of attributes to pass down from my outer class, and loop over them and send, something like this:

# not tested
['x', 'y', 'z'].each{|a|@formula.send("#{a.to_sym}=", self.send("#{a.to_sym}") }

Any other ruby magic or patterns I should be considering?

Thanks,

  • 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-19T05:15:44+00:00Added an answer on May 19, 2026 at 5:15 am

    Sounds like you’re look for a Strategy pattern to plug in the formula and then maybe a Facade if you don’t want to call the formula’s attribute via the formula instance.

    Easy way to make a Strategy is to make an instance of Formula one of Outer’s attributes:

    class Outer
    
      attr_accessor :formula #this bit is Strategy
    
      def x #this bit is Facade
        @formula.x
      end
    
      def calculate #Facade
        @formula.calculate
      end
    
    end
    
    outer1 = Outer.new
    
    outer1.formula = Formula17.new
    
    #this is the same
    outer1.formula.x = 2
    outer1.x = 2
    
    #these are the same
    puts outer1.formula.x
    puts outer1.x
    
    #and these are the same
    puts outer1.formula.calculate
    puts outer1.calculate
    
    #and this would be the same as the above
    formula17 = Formula17.new
    formula17.x = 2
    outer1 = Outer.new
    outer1.formula = formula17
    

    to deal with lots of accessors perhaps you could try method missing to either call, or define and call the methods for you as they’re called?

    def method_missing(meth, *args, &block)
      if @formula.respond_to?(meth)
        @formula.send(meth, *args, &block)
      end
      else
        super(meth, *args, &block)
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry, I know this is a very lame question to ask and not of
Sorry about the lame title. I have a project I'm working on and I
Sorry if the title is not clear enough, I have <a> elements with the
I am new to php, so sorry if this is lame. I have a
Sorry the title isn't more help. I have a database of media-file URLs that
Sorry for a long question and not a very descriptive title, but my problem
Sorry if this is a dup; I haven't found any questions that pose quite
Sorry, I'm sure this is simple but I'm tired and can't figure it out.
Sorry for the unhelpful title, but hopefully I can explain this well enough. Lets
Sorry if this is a stupid question... I've developed an application that creates absolute

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.