よく忘れるので。
- keyとvalueを
string
からinteger
にしたい
hash = { '1' => '2', '3' => '4' }
Hash[*(hash.to_a.flatten.map(&:to_i))]
-
ActiveRecord_Relation
を{ id: somthing, id: something }
みたいにしたい。
users = User.limit(10)
Hash[*users.map { |u| [u.id, u.point] }.flatten]
- hash間の差分を出したい
hash_a = { 1 => 2, 3 => 5, 4 => 6 }
hash_b = { 1 => 2, 3 => 4 }
diff = (hash_a.to_a - hash_b.to_a).to_h