Small football table builder in Ruby
Note that uniq is not in-place, uniq! is. Otherwise, I guess your code is pretty good if you like imperative style (maybe some unnecessary comments could be removed, though). Personally, I prefer a functional approach: less statements, more expressions. If you open a console and play with the input data, applying transformations, you'll see it's not as difficult as it would seem at first. In this case I'd write:

goals_cmp_to_points = {-1 =&gt; 0, 0 =&gt; 1, 1 =&gt; 3}
team_results = match_results.flat_map do |result|
  [[:home, :away], [:away, :home]].map do |side1, side2|
    goals_cmp = result[:"#{side1}_score"] &lt;=&gt; result[:"#{side2}_score"]
    {
      :team =&gt; result[:"#{side1}_team"],
      :goals =&gt; result[:"#{side1}_score"],
      :points =&gt; goals_cmp_to_points[goals_cmp],
    }
  end
end

#[{:team=&gt;"Honduras", :goals=&gt;0, :points=&gt;0},
# {:team=&gt;"Chile", :goals=&gt;1, :points=&gt;3},
# [...]
# {:team=&gt;"Switzerland", :goals=&gt;0, :points=&gt;1}]

table = team_results.group_by { |r| r[:team] }.map do |team, results_for_team|
  {
    :team =&gt; team, 
    :total_goals =&gt; results_for_team.map { |r| r[:goals] }.reduce(0, :+),
    :total_points =&gt; results_for_team.map { |r| r[:points] }.reduce(0, :+),
  }
end
sorted_table = table.sort_by { |tr| tr.values_at(:total_points, :total_goals) }.reverse

#[{:team=&gt;"Spain", :total_goals=&gt;4, :total_points=&gt;6},
# {:team=&gt;"Chile", :total_goals=&gt;3, :total_points=&gt;6},
# {:team=&gt;"Switzerland", :total_goals=&gt;1, :total_points=&gt;4},
# {:team=&gt;"Honduras", :total_goals=&gt;0, :total_points=&gt;1}]