Ruby 2.5.0 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Hashクラス > transform_keys!
transform_keys! {|key| ... } -> self
[permalink][rdoc]transform_keys! -> Enumerator
すべてのキーに対してブロックを呼び出した結果でハッシュのキーを変更します。値は変化しません。
h = { a: 1, b: 2, c: 3 }
h.transform_keys! {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys!(&:to_sym) # => {:a=>1, :b=>2, :c=>3}
h.transform_keys!.with_index {|k, i| "#{k}.#{i}" }
# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
[SEE_ALSO] Hash#transform_keys
[SEE_ALSO] Hash#transform_values
[SEE_ALSO] Hash#transform_values!