るりまサーチ

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

別のキーワード

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

クラス

キーワード

検索結果

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

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

...1.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"=>300}
h1.merge(h2, h3) {|key, oldval, newv...
...al| newval - oldval}
#=> {"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.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"}
//}

//emlist[][ruby]{
class
Foo
def to_hash
{:Australia => 'Sydney',
:France => 'Paris'
}
end
end...

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

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

...1.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"=>300}
h1.merge(h2, h3) {|key, oldval, newv...
...al| newval - oldval}
#=> {"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.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"}
//}

//emlist[][ruby]{
class
Foo
def to_hash
{:Australia => 'Sydney',
:France => 'Paris'
}
end
end...

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

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

...//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, "c"=>300}
h1 # => {...
...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"}
//}

//emlist[][ruby]{
class
Foo
def...
...{:Australia => 'Sydney',
:France => 'Paris'
}
end
end

h = {:Germany => 'Berlin',
:Australia => 'Canberra',
:France => 'Paris'
}

# 暗黙の変換
p h.merge(Foo.new) # => {:Germany=>"Berlin", :Australia=>"Sydney", :France=>"Paris"}
//}

@see Hash#update,Hash#replace...

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

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

...//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, "c"=>300}
h1 # => {...
...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"}
//}

//emlist[][ruby]{
class
Foo
def...
...{:Australia => 'Sydney',
:France => 'Paris'
}
end
end

h = {:Germany => 'Berlin',
:Australia => 'Canberra',
:France => 'Paris'
}

# 暗黙の変換
p h.merge(Foo.new) # => {:Germany=>"Berlin", :Australia=>"Sydney", :France=>"Paris"}
//}

@see Hash#update,Hash#replace...

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

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

...{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...

絞り込み条件を変える

Object#to_hash -> Hash (20.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}
//}...