Ruby 2.2.0 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Hashクラス > to_h

instance method Hash#to_h

to_h -> self | Hash[permalink][rdoc]

self を返します。Hash クラスのサブクラスから呼び出した場合は self を Hash オブジェクトに変換します。



hash = {}
p hash.to_h      # => {}
p hash.to_h == hash # => true

class MyHash < Hash;end
my_hash = MyHash.new
p my_hash.to_h        # => {}
p my_hash.class       # => MyHash
p my_hash.to_h.class  # => Hash