このマニュアルは既にメンテナンスが終了したバージョンの Ruby を対象としています。 最新版のマニュアルへ

Ruby 2.3.0 リファレンスマニュアル

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