学習ログ group_by

(1..30).to_a.shuffle.group_by { |n| 
  n <= 10 ? "1..10" : 
  n <= 20 ? "11..20" : 
            "21..30" 
}
# 実行結果例
#{ "1..10"=>[2, 5, 8, 1, 10, 6, 9, 7, 3, 4],  
#  "11..20"=>[14, 15, 20, 16, 11, 12, 18, 19, 13, 17], 
#  "21..30"=>[26, 24, 29, 23, 28, 21, 22, 30, 27, 25] }
data = [[:c, 88],[:a, 10], [:b, 11],[:c, 12],[:b, 13]]
data.group_by{|first,second| first}

# {:a=>[[:a, 10]], 
#  :b=>[[:b, 11], [:b, 13]], 
#  :c=>[[:c, 88], [:c, 12]]}