title: Searching and comparing ActiveRecord attributes to find largest value
body: <p>I have a model that would look something like:</p>
  
  <pre><code>my_diet = Diet.new
  my_diet.food_type_1 = "beef"
  my_diet.food_type_1_percentage = 40
  my_diet.food_type_2 = "carrots"
  my_diet.food_type_2_percentage = 50
  my_diet.food_type_3 = "beans"
  my_diet.food_type_3_percentage = 5
  my_diet.food_type_4 = "chicken"
  my_diet.food_type_4_percentage = 5
  </code></pre>
  
  <p>I need to find which food_type has the highest percentage. So far I've tried creating a hash out of the attibutes and percentages then sorting the hash (see below) but it feels like there must be a cleaner way to do it.</p>
  
  <pre><code>  food_type_percentages = { :food_type_1 =&gt; my_diet.foo_type_percentage_1_percentage.nil? ? 0 : my_dient.food_type_1_percentage,
                              :food_type_2 =&gt; my_diet.foo_type_percentage_2_percentage.nil? ? 0 : my_dient.food_type_2_percentage,
                              :food_type_3 =&gt; my_diet.foo_type_percentage_3_percentage.nil? ? 0 : my_dient.food_type_3_percentage,
                              :food_type_4 =&gt; my_diet.foo_type_percentage_4_percentage.nil? ? 0 : my_dient.food_type_4_percentage
    }
    food_type_percentages.sort {|a,b| a[1]&lt;=&gt;b[1]}.last
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Thanks!</p>