2件ヒット
[1-2件を表示]
(0.151秒)
クラス
- Hash (1)
- OpenStruct (1)
検索結果
-
Hash
# to _ h -> self | Hash (54697.0) -
self を返します。Hash クラスのサブクラスから呼び出した場合は 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
//} -
OpenStruct
# to _ h -> { Symbol => object } (54643.0) -
self を各要素の名前をキー(Symbol)、要素が値のハッシュに変換して返 します。
self を各要素の名前をキー(Symbol)、要素が値のハッシュに変換して返
します。
//emlist[例][ruby]{
require 'ostruct'
data = OpenStruct.new("country" => "Australia", :capital => "Canberra")
data.to_h # => {:country => "Australia", :capital => "Canberra" }
//}