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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:11:27+00:00 2026-06-14T20:11:27+00:00

Say I have a set of attributes on my Client model like this: #

  • 0

Say I have a set of attributes on my Client model like this:

#  firm_size                 :float
#  priority_level            :float
#  inflection_point          :float
#  personal_priority         :float
#  sales_priority            :float
#  sales_team_priority       :float
#  days_since_contact        :float
#  does_client_vote          :float
#  did_client_vote_for_us    :float
#  days_until_next_vote      :float
#  does_client_vote_ii       :float
#  did_client_vote_ii_for_us :float
#  days_until_vote_ii        :float

And I need to run a check on each attribute like this:

max = Max.find_or_create_by_user_id(:user_id => current_user.id)

if client.firm.size > max.firm_size
    max.firm_size = client.firm.size
end

if client.inflection_point > max.inflection_point
    max.inflection_point = client.inflection_point
end

And so on for the rest of the attributes, but this seems quite un-DRY to me.

How do I do this in an elegant way, without having to type out 1 billion if statements for all the attributes?

  • 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-14T20:11:28+00:00Added an answer on June 14, 2026 at 8:11 pm

    If you put all the attributes in an array, you could iterate over it and use some metaprogramming to only have to write the logic once:

    good_attrs = %w(firm_size priority_level ...)
    
    good_attrs.each do |attr|
      if client.send(attr) > max.send(attr)
        max.send("#{attr}=", client.send(attr)
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a class that looks like this (get/set omited): class InfoClass{ String
let's say I have this set of HTML-markup and CSS #CSS .inputhelp_text { background:
Lets say I have model inheritance set up in the way defined below. class
I have set up a Core Data model where I have two objects, say
let's say I have 2 classes like this: public class Foo { [Required] public
Let's say I have a set of Django Models: class Article(models.Model): title = models.CharField(max_length=100,
I'd like an input field that I can have javascript set certain attributes for,
Say I have the following set of classes, is it possible for the attributes
Let's say I have a model called Theme, which has several attributes setting interface
Let's say I have a vector where I've set a few attributes: vec <-

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.