title: Combine Rails 3 scope into class method
body: <p>I have 4 Rails 3 scopes that I would like to simplify:</p>
  
  <pre><code>  scope :age_0, lambda {
      where("available_at IS NULL OR available_at &lt; ?", Date.today + 30.days)
    }
    scope :age_30, lambda {
      where("available_at &gt;= ? AND available_at &lt; ?", Date.today + 30.days, Date.today + 60.days)
    }
    scope :age_60, lambda {
      where("available_at &gt;= ? AND available_at &lt; ?", Date.today + 60.days, Date.today + 90.days)
    }
    scope :age_90, lambda {
      where("available_at &gt;= ?", Date.today + 90.days)
    }
  </code></pre>
  
  <p>I thought about a class method:</p>
  
  <pre><code>def self.aging(days)
  
    joins(:profile).where("available_at IS NULL OR available_at &lt; ?", Date.today + 30.days) if days==0
    joins(:profile).where("available_at &gt;= ? AND available_at &lt; ?", Date.today + 30.days, Date.today + 60.days) if days==30
    joins(:profile).where("available_at &gt;= ? AND available_at &lt; ?", Date.today + 60.days, Date.today + 90.days) if days==60
    joins(:profile).where("available_at &gt;= ?", Date.today + 90.days) if days==90
  
  end
  </code></pre>
  
  <p>But I don't know what to return to ensure that it will be compatible with Rails 3 scopes.</p>
  
  <p>Is this a good approach?  Is there a better way to do this?</p>
  
  <p>** edit **
  I updated the method's logic.  The if test doesn't seem to work as I expect.</p>