LoginSignup
6
6

More than 5 years have passed since last update.

Hashの再構築

Posted at

mapはHashではなくArrayを返す.(当たり前だけど)

h = {"a"=> 1, "b"=>2}
h.map{|k, v| [k.upcase. v] } => [["A", 1], ["B", 2]]

hがHashだとわかっているならこういうコードが手っ取り早い.

Hash[h.map{|k, v| k = k.upcase; [k, v] }]
=> {"A"=>1, "B"=>2}
6
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6