{"author_name":"thinca","html":"<iframe src=\"https://hatenablog-parts.com/embed?url=https%3A%2F%2Fthinca.hatenablog.com%2Fentry%2F20150215%2F1423965924\" title=\" Ruby \u306e Hash \u3067\u5024\u3060\u3051 map \u3067\u5909\u63db\u3057\u305f\u304b\u3063\u305f - \u6c38\u9060\u306b\u672a\u5b8c\u6210\" class=\"embed-card embed-blogcard\" scrolling=\"no\" frameborder=\"0\" style=\"display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;\"></iframe>","blog_title":"\u6c38\u9060\u306b\u672a\u5b8c\u6210","url":"https://thinca.hatenablog.com/entry/20150215/1423965924","blog_url":"https://thinca.hatenablog.com/","categories":["ruby"],"width":"100%","author_url":"https://blog.hatena.ne.jp/thinca/","version":"1.0","provider_url":"https://hatena.blog","provider_name":"Hatena Blog","type":"rich","height":"190","image_url":null,"published":"2015-02-15 11:05:24","title":" Ruby \u306e Hash \u3067\u5024\u3060\u3051 map \u3067\u5909\u63db\u3057\u305f\u304b\u3063\u305f","description":"hash = {a: 1, b: 2, c: 3} hash2 = hash.map {|k, v| [k, v * 2] }.to_h p hash2 # => {a: 2, b: 4, c: 6} \u3081\u3093\u3069\u304f\u3055\u3044\u3002Scala \u306b\u306f mapValues \u3068\u3044\u3046\u306e\u304c\u3042\u308b\u3089\u3057\u3044\u3002Ruby \u3067\u66f8\u304f\u306a\u3089\u3053\u3046\u304b\u306a\u3002 class Hash def map_values(&block) dup.map_values!(&block) end def map_values!(&block) update(self) {|_, v| block.call(v) } end end hash = {a: 1, b\u2026"}