るりまサーチ

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

別のキーワード

  1. openssl new
  2. _builtin new
  3. rexml/document new
  4. resolv new
  5. socket new

クラス

検索結果

Hash#to_h -> self | Hash (18158.0)

self を返します。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] } # => {"A"=>65, "B"=>66}
//}

@see Enumerable#map...

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

self を返します。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] } # => {"A"=>65, "B"=>66}
//}

@see Enumerable#map...

Hash#to_h -> self | Hash (18151.0)

self を返します。Hash クラスのサブクラスから呼び出した場合は self を 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
//}...

Object#to_hash -> Hash (6114.0)

オブジェクトの Hash への暗黙の変換が必要なときに内部で呼ばれます。 デフォルトでは定義されていません。

...すべての場面で代置可能であるような、
* ハッシュそのものとみなせるようなもの
という厳しいものになっています。

//emlist[][ruby]{
class
Foo
def to_hash
{'as' => 24}
end
end

it = Foo.new
p({:as => 12}.merge(it)) #=> {"as"=>24, :as=>12}
//}...