るりまサーチ

最速Rubyリファレンスマニュアル検索!
607件ヒット [301-400件を表示] (0.193秒)
トップページ > クエリ:t[x] > クエリ:Ruby[x] > 種類:インスタンスメソッド[x] > クエリ:r[x] > クエリ:ruby[x] > クラス:Hash[x]

別のキーワード

  1. rbconfig ruby
  2. fiddle ruby_free
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

キーワード

検索結果

<< < ... 2 3 4 5 6 ... > >>

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

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

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

self と others に同じキーがあった場合はブロック付きか否かで
判定方法が違います。ブロック付きのときはブ...
...に others の値を使います。

othersがハッシュではない場合、othersのメソッドto_hashを使って暗黙の変換を試みます。

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

//emlist[][ruby]{
h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 246, "c" => 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, ol...

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

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

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

self と other に同じキーがあった場合はブロック付きか否かで
判定方法が違います。ブロック付きのときはブロックを...
...常に other の値を使います。

otherがハッシュではない場合、otherのメソッドto_hashを使って暗黙の変換を試みます。

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

//emlist[][ruby]{
h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 254, "c" => 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, "...

Hash#merge!(other) -> self (6226.0)

selfとotherのハッシュの内容をマージ(統合)します。

...selfとotherのハッシュの内容をマージ(統合)します。

デフォルト値はselfの設定のままです。

self と other に同じキーがあった場合はブロック付きか否かで
判定方法が違います。ブロック付きのときはブロックを呼び出して...
...常に other の値を使います。

otherがハッシュではない場合、otherのメソッドto_hashを使って暗黙の変換を試みます。

@param other マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マー...
...mlist[][ruby]{
h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 254, "c" => 300 }
h1.merge!(h2) # => {"a"=>100, "b"=>254, "c"=>300}
h1 # => {"a"=>100, "b"=>254, "c"=>300}
//}

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

p foo.update(bar) #...

Hash#update(other) -> self (6226.0)

selfとotherのハッシュの内容をマージ(統合)します。

...selfとotherのハッシュの内容をマージ(統合)します。

デフォルト値はselfの設定のままです。

self と other に同じキーがあった場合はブロック付きか否かで
判定方法が違います。ブロック付きのときはブロックを呼び出して...
...常に other の値を使います。

otherがハッシュではない場合、otherのメソッドto_hashを使って暗黙の変換を試みます。

@param other マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マー...
...mlist[][ruby]{
h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 254, "c" => 300 }
h1.merge!(h2) # => {"a"=>100, "b"=>254, "c"=>300}
h1 # => {"a"=>100, "b"=>254, "c"=>300}
//}

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

p foo.update(bar) #...

Hash#update(other) {|key, self_val, other_val| ... } -> self (6226.0)

selfとotherのハッシュの内容をマージ(統合)します。

...selfとotherのハッシュの内容をマージ(統合)します。

デフォルト値はselfの設定のままです。

self と other に同じキーがあった場合はブロック付きか否かで
判定方法が違います。ブロック付きのときはブロックを呼び出して...
...常に other の値を使います。

otherがハッシュではない場合、otherのメソッドto_hashを使って暗黙の変換を試みます。

@param other マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マー...
...mlist[][ruby]{
h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 254, "c" => 300 }
h1.merge!(h2) # => {"a"=>100, "b"=>254, "c"=>300}
h1 # => {"a"=>100, "b"=>254, "c"=>300}
//}

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

p foo.update(bar) #...

絞り込み条件を変える

Hash#delete_if -> Enumerator (6214.0)

キーと値を引数としてブロックを評価した結果が真であ るような要素を self から削除します。

...ら削除します。

delete_if は常に self を返します。
r
eject! は、要素を削除しなかった場合には nil を返し、
そうでなければ self を返します。

ブロックを省略した場合は Enumerator を返します。

//emlist[例][ruby]{
h = { 2 => "8" ,4 => "6...
...> "2" }

p h.reject!{|key, value| key.to_i < value.to_i } #=> { 6 => "4", 8 => "2" }
p h #=> { 6 => "4", 8 => "2" }

p h.delete_if{|key, value| key.to_i < value.to_i } #=> { 6 => "4", 8 => "2" }
p h.reject!{|key, value| key.to_i < value.to_i } #=> n...
...il
//}

@see Hash#reject,Hash#delete
@see Hash#keep_if,Hash#select!...

Hash#flatten(level = 1) -> Array (6214.0)

自身を平坦化した配列を生成して返します。

...
Array#flatten と違って、デフォルトではこのメソッドは自身を
再帰的に平坦化しません。level を指定すると指定されたレベルまで
再帰的に平坦化します。

@param level 展開するレベル

//emlist[例][ruby]{
a = {1=> "one", 2 => [2,"two"],...
...3 => "three"}
a.flatten #=> [1, "one", 2, [2, "two"], 3, "three"]
a.flatten(1) #=> [1, "one", 2, [2, "two"], 3, "three"]
a.flatten(2) #=> [1, "one", 2, 2, "two", 3, "three"]
a.flatten(0) #=> [[1, "one"], [2, [2, "two"]], [3, "three"]]
a.flatten(-1) #=> [1, "one", 2, 2, "two", 3, "three"]
//}...
...@see Array#flatten...

Hash#inspect -> String (6214.0)

ハッシュの内容を人間に読みやすい文字列にして返します。

...ハッシュの内容を人間に読みやすい文字列にして返します。

//emlist[例][ruby]{
h = { "c" => 300, "a" => 100, "d" => 400 }
h.inspect # => "{\"c\"=>300, \"a\"=>100, \"d\"=>400}"
//}...

Hash#keep_if -> Enumerator (6214.0)

キーと値を引数としてブロックを評価した結果が真であるような要素を self に残します。

...
filter! と select! はオブジェクトが変更された場合に self を、
されていない場合に nil を返します。

ブロックが与えられなかった場合は、自身と keep_if から生成した
Enumerator オブジェクトを返します。

//emlist[例][ruby]{
h1 =...
...{}
c = ("a".."g")
c.each_with_index {|e, i| h1[i] = e }

h2 = h1.dup
h1.select! # => #<Enumerator: {0=>"a", 1=>"b", 2=>"c", 3=>"d", 4=>"e", 5=>"f", 6=>"g"}:select!>

h1.select! { |k, v| k % 3 == 0 } # => {0=>"a", 3=>"d", 6=>"g"}
h1.select! { |k, v| true } # => nil
h2.keep_if { |k, v| k % 3...
...== 0 } # => {0=>"a", 3=>"d", 6=>"g"}
h2.keep_if { |k, v| true } # => {0=>"a", 3=>"d", 6=>"g"}
//}

@see Hash#select, Hash#delete_if, Hash#reject!...

Hash#length -> Integer (6214.0)

ハッシュの要素の数を返します。

...ハッシュの要素の数を返します。

//emlist[][ruby]{
h = { "d" => 100, "a" => 200, "v" => 300, "e" => 400 }
h.length #=> 4
h.size #=> 4
h.delete("a") #=> 200
h.length #=> 3
h.size #=> 3
//}...

絞り込み条件を変える

Hash#replace(other) -> self (6214.0)

ハッシュの内容を other の内容で置き換えます。

...内容を other の内容で置き換えます。

デフォルト値の設定もotherの内容になります。
otherがハッシュではない場合、otherのメソッドto_hashを使って暗黙の変換を試みます。

self = other.to_hash.dup と同じです。

@param other ハッシュ...
... to_hash でハッシュに変換できるオブジェクトです。
@return self を返します。

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

foo.replace(bar)
p foo #=> {2=>"B", 3=>"C"}

zoo = {}
zoo = bar.dup
p zoo #=> {2=>"B", 3=>"C"}

class Foo
def to_hash...
...{:japan => 'kyoto'}
end
end

h = Hash.new
h.replace(Foo.new) #暗黙の変換
p h #=> {:japan=>"kyoto"}
//}

@see Hash#dup,Hash#merge,Object#to_hash...

Hash#select -> Enumerator (6214.0)

key, value のペアについてブロックを評価し,真となるペアだけを含む ハッシュを生成して返します。

...った場合は、自身と select から生成した
Enumerator オブジェクトを返します。

//emlist[][ruby]{
h = { "a" => 100, "b" => 200, "c" => 300 }
h.select {|k,v| k > "a"} #=> {"b" => 200, "c" => 300}
h.select {|k,v| v < 200} #=> {"a" => 100}
//}


@see Hash#select!, Hash#reject...

Hash#store(key, value) -> object (6214.0)

key に対して value を関連づけます。value を返し ます。

...key に対して value を関連づけます。value を返し
ます。

@param key キーを指定します。
@param value 値を指定します。


//emlist[例][ruby]{
h = {}

h[:key] = "value"
p h #=>{:key => "value"}
//}

@see Hash#[]...
<< < ... 2 3 4 5 6 ... > >>