るりまサーチ

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

別のキーワード

  1. _builtin hash
  2. hash []
  3. matrix hash
  4. dbm to_hash
  5. _builtin to_hash

ライブラリ

キーワード

検索結果

<< 1 2 3 ... > >>

Hash#>(other) -> bool (39144.0)

other が self のサブセットである場合に真を返します。

...サブセットである場合に真を返します。

@param other 自身と比較したい Hash オブジェクトを指定します。

//emlist[例][ruby]{
h1 = {a:1, b:2}
h2 = {a:1, b:2, c:3}
h1 > h2 # => false
h2 > h1 # => true
h1 > h1 # => false
//}

@see Hash#<=, Hash#<, Hash#>=...

Hash#to_hash -> self (27251.0)

self を返します。

...self を返します。

//emlist[例][ruby]{
hash
= {}
p hash.to_hash # => {}
p hash.to_hash == hash # => true
//}

@see Object#to_hash, Hash#to_h...

Hash#hash -> Integer (27215.0)

自身が保持するキーと値のハッシュ値を元にして算出した整数を返します。 自身が保持するキーや値が変化すればこのメソッドが返す値も変化します。

...自身が保持するキーと値のハッシュ値を元にして算出した整数を返します。
自身が保持するキーや値が変化すればこのメソッドが返す値も変化します。

//emlist[例][ruby]{
a = {}
p a.hash #=> 0
a[1] = :x
p a.hash #=> 329543
//}...

Hash#rehash -> self (27214.0)

キーのハッシュ値を再計算します。

...raise RuntimeError Hash#eachなどのイテレータの評価途中でrehashすると発生します。
@return selfを返します。

//emlist[例][ruby]{
a = [ "a", "b" ]
h = { a => 100 }

p h[a] #=> 100

a[0] = "z"
p h[a] #=> nil

h.rehash
p h[a] #=> 100
//}

@see Object#hash...

Hash#>=(other) -> bool (27126.0)

other が self のサブセットか同じである場合に真を返します。

...セットか同じである場合に真を返します。

@param other 自身と比較したい Hash オブジェクトを指定します。

//emlist[例][ruby]{
h1 = {a:1, b:2}
h2 = {a:1, b:2, c:3}
h1 >= h2 # => false
h2 >= h1 # => true
h1 >= h1 # => true
//}

@see Hash#<=, Hash#<, Hash#>...

絞り込み条件を変える

Hash#transform_keys(hash) -> Hash (21329.0)

すべてのキーに対してブロックを呼び出した結果で置き換えたハッシュを返します。 値は変化しません。

...ん。

@param hash 置き換え前のキーから置き換え後のキーへのハッシュを指定します。

//emlist[例][ruby]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys(a: "a", d: "d") # => {"a"=>1, :b=>2, :c=>3}
h.transform_key...
...s(&:to_s) # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys.with_index {|k, i| "#{k}.#{i}" }
# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}

@see Hash#transform_keys!
@see Hash#transform_values
@see Hash#transform_values!...

Hash#to_h -> self | Hash (21308.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.clas...
...=> 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 (21308.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.clas...
...=> 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 (21295.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.clas...
...s # => MyHash
p my_hash.to_h.class # => Hash
//}...

Hash#compact -> Hash (21255.0)

compact は自身から value が nil のもの取り除いた Hash を生成して返します。 compact! は自身から破壊的に value が nil のものを取り除き、変更が行われた場合は self を、そうでなければ nil を返します。

... Hash を生成して返します。 compact! は自身から破壊的に value が nil のものを取り除き、変更が行われた場合は self を、そうでなければ nil を返します。


//emlist[例][ruby]{
hash
= {a: 1, b: nil, c: 3}
p hash.compact #=> {:a=>1, :c=>3}
p hash...
...#=> {:a=>1, :b=>nil, :c=>3}
hash
.compact!
hash
#=> {:a=>1, :c=>3}
p hash.compact! #=> nil
//}

@see Array#compact...

絞り込み条件を変える

Hash#merge(*others) -> Hash (21234.0)

selfとothersのハッシュの内容を順番にマージ(統合)した結果を返します。 デフォルト値はselfの設定のままです。

...to_hashを使って暗黙の変換を試みます。

@param others マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マージした結果を返します

//emlist[][ruby]{
h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 246,...
...> 300 }
h3 = { "b" => 357, "d" => 400 }
h1.merge #=> {"a"=>100, "b"=>200}
h1.merge(h2) #=> {"a"=>100, "b"=>246, "c"=>300}
h1.merge(h2, h3) #=> {"a"=>100, "b"=>357, "c"=>300, "d"=>400}
h1.merge(h2) {|key, oldval, newval| newval - oldval}
#=> {"a"=>100, "b"=>46, "c"=>...
...#=> {"a"=>100, "b"=>311, "c"=>300, "d"=>400}
h1 #=> {"a"=>100, "b"=>200}
//}

//emlist[][ruby]{
foo = {1 => 'a', 2 => 'b', 3 => 'c'}
bar = {2 => 'B', 3 => 'C', 4 => 'D'}

p foo.merge(bar)
# => {1=>"a", 2=>"B", 3=>"C", 4=>"D"}
p foo # => {1=>"a", 2=>"b", 3=>"c"}

p foo...

Hash#merge(*others) {|key, self_val, other_val| ... } -> Hash (21234.0)

selfとothersのハッシュの内容を順番にマージ(統合)した結果を返します。 デフォルト値はselfの設定のままです。

...to_hashを使って暗黙の変換を試みます。

@param others マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マージした結果を返します

//emlist[][ruby]{
h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 246,...
...> 300 }
h3 = { "b" => 357, "d" => 400 }
h1.merge #=> {"a"=>100, "b"=>200}
h1.merge(h2) #=> {"a"=>100, "b"=>246, "c"=>300}
h1.merge(h2, h3) #=> {"a"=>100, "b"=>357, "c"=>300, "d"=>400}
h1.merge(h2) {|key, oldval, newval| newval - oldval}
#=> {"a"=>100, "b"=>46, "c"=>...
...#=> {"a"=>100, "b"=>311, "c"=>300, "d"=>400}
h1 #=> {"a"=>100, "b"=>200}
//}

//emlist[][ruby]{
foo = {1 => 'a', 2 => 'b', 3 => 'c'}
bar = {2 => 'B', 3 => 'C', 4 => 'D'}

p foo.merge(bar)
# => {1=>"a", 2=>"B", 3=>"C", 4=>"D"}
p foo # => {1=>"a", 2=>"b", 3=>"c"}

p foo...

Hash#merge(other) -> Hash (21234.0)

selfとotherのハッシュの内容をマージ(統合)した結果を返します。デフォルト値はselfの設定のままです。

...to_hashを使って暗黙の変換を試みます。

@param other マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マージした結果を返します

//emlist[][ruby]{
h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 254,...
...=> 300 }
h1.merge() # => {"a"=>100, "b"=>200}
h1.merge(h2) # => {"a"=>100, "b"=>254, "c"=>300}
h1.merge(h2){|key, oldval, newval| newval - oldval}
# => {"a"=>100, "b"=>54, "c"=>300}
h1 # => {"a"=>100, "b"=>200}
//}

//emlist[][ruby]{
foo = {1 => 'a', 2 => 'b', 3 =>...
...bar = {2 => 'B', 3 => 'C', 4 => 'D'}

p foo.merge(bar)
# => {1=>"a", 2=>"B", 3=>"C", 4=>"D"}
p foo # => {1=>"a", 2=>"b", 3=>"c"}

p foo.merge!(bar) {|key, foo_val, bar_val| foo_val + bar_val }
# => {1=>"a", 2=>"bB", 3=>"cC", 4=>"D"}
p foo # => {1=>"a", 2=>"bB", 3=>"cC", 4=>"D"}
//}...

Hash#merge(other) {|key, self_val, other_val| ... } -> Hash (21234.0)

selfとotherのハッシュの内容をマージ(統合)した結果を返します。デフォルト値はselfの設定のままです。

...to_hashを使って暗黙の変換を試みます。

@param other マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マージした結果を返します

//emlist[][ruby]{
h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 254,...
...=> 300 }
h1.merge() # => {"a"=>100, "b"=>200}
h1.merge(h2) # => {"a"=>100, "b"=>254, "c"=>300}
h1.merge(h2){|key, oldval, newval| newval - oldval}
# => {"a"=>100, "b"=>54, "c"=>300}
h1 # => {"a"=>100, "b"=>200}
//}

//emlist[][ruby]{
foo = {1 => 'a', 2 => 'b', 3 =>...
...bar = {2 => 'B', 3 => 'C', 4 => 'D'}

p foo.merge(bar)
# => {1=>"a", 2=>"B", 3=>"C", 4=>"D"}
p foo # => {1=>"a", 2=>"b", 3=>"c"}

p foo.merge!(bar) {|key, foo_val, bar_val| foo_val + bar_val }
# => {1=>"a", 2=>"bB", 3=>"cC", 4=>"D"}
p foo # => {1=>"a", 2=>"bB", 3=>"cC", 4=>"D"}
//}...
<< 1 2 3 ... > >>