るりまサーチ

最速Rubyリファレンスマニュアル検索!
17件ヒット [1-17件を表示] (0.052秒)

別のキーワード

  1. argf.class lines
  2. argf.class each
  3. argf.class each_line
  4. class new
  5. argf.class gets

検索結果

Hash#to_h -> self | Hash (28.0)

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

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

//emlist[例][ruby]{
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
//}...
...# => MyHash
p my_hash.to_h.class # => Hash
//}

ブロックを指定すると各ペアでブロックを呼び出し、
その結果をペアとして使います。
//emlist[ブロック付きの例][ruby]{
hash
= { "a" => 97, "b" => 98 }
hash
.to_h {|key, value| [key.upcase, value-32] } # =>...

Hash#to_h {|key, value| block } -> Hash (28.0)

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

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

//emlist[例][ruby]{
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
//}

ブロックを指定すると各ペアでブロックを呼び出し、
その結果をペアとして使います。
//emlist[ブロック付きの例][ruby]{
hash
= { "a" => 97, "b" => 98 }
hash
.to_h {|key, value| [key.upcase, value-32] } # =>...