るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

キーワード

検索結果

Hash#fetch(key) -> object (18164.0)

key に関連づけられた値を返します。該当するキーが登録されてい ない時には、引数 default が与えられていればその値を、ブロッ クが与えられていればそのブロックを評価した値を返します。

...default が与えられていればその値を、ブロッ
クが与えられていればそのブロックを評価した値を返します。

fetch
はハッシュ自身にデフォルト値が設定されていても単に無視します(挙動に変化がありません)。

@param key 探...
...//emlist[例][ruby]{
h = {one: nil}
p h[:one],h[:two] #=> nil,nil これではキーが存在するのか判別できない。
p h.fetch(:one) #=> nil
p h.fetch(:two) # エラー key not found (KeyError)
p h.fetch(:two,"error")...
...#=> "error"
p h.fetch(:two){|key|"#{key} not exist"} #=> "two not exist"
p h.fetch(:two, "error"){|key| #=> "two not exist"
"#{key} not exist" # warning: block supersedes default value argument
} # 警告が...

Hash#fetch(key) {|key| ... } -> object (18164.0)

key に関連づけられた値を返します。該当するキーが登録されてい ない時には、引数 default が与えられていればその値を、ブロッ クが与えられていればそのブロックを評価した値を返します。

...default が与えられていればその値を、ブロッ
クが与えられていればそのブロックを評価した値を返します。

fetch
はハッシュ自身にデフォルト値が設定されていても単に無視します(挙動に変化がありません)。

@param key 探...
...//emlist[例][ruby]{
h = {one: nil}
p h[:one],h[:two] #=> nil,nil これではキーが存在するのか判別できない。
p h.fetch(:one) #=> nil
p h.fetch(:two) # エラー key not found (KeyError)
p h.fetch(:two,"error")...
...#=> "error"
p h.fetch(:two){|key|"#{key} not exist"} #=> "two not exist"
p h.fetch(:two, "error"){|key| #=> "two not exist"
"#{key} not exist" # warning: block supersedes default value argument
} # 警告が...

Hash#fetch(key, default) -> object (18164.0)

key に関連づけられた値を返します。該当するキーが登録されてい ない時には、引数 default が与えられていればその値を、ブロッ クが与えられていればそのブロックを評価した値を返します。

...default が与えられていればその値を、ブロッ
クが与えられていればそのブロックを評価した値を返します。

fetch
はハッシュ自身にデフォルト値が設定されていても単に無視します(挙動に変化がありません)。

@param key 探...
...//emlist[例][ruby]{
h = {one: nil}
p h[:one],h[:two] #=> nil,nil これではキーが存在するのか判別できない。
p h.fetch(:one) #=> nil
p h.fetch(:two) # エラー key not found (KeyError)
p h.fetch(:two,"error")...
...#=> "error"
p h.fetch(:two){|key|"#{key} not exist"} #=> "two not exist"
p h.fetch(:two, "error"){|key| #=> "two not exist"
"#{key} not exist" # warning: block supersedes default value argument
} # 警告が...

Array#fetch_values(*indexes) -> Array (12245.0)

引数で指定されたインデックスに対する値の配列を返します。

...mlist[例][ruby]{
ary = ["a", "b", "c"]

ary.fetch_values(0, 2) # => ["a", "c"]
ary.fetch_values(-1, 1) # => ["d", "b"]
ary.fetch_values(0, 10) # => index 10 outside of array bounds: -3...3 (IndexError)
ary.fetch_values(0, 10) { |i| i.to_s } # => ["a", "10"]
//}

@see Array#values_at, Array#fetch...

Array#fetch_values(*indexes) { |index| ... } -> Array (12245.0)

引数で指定されたインデックスに対する値の配列を返します。

...mlist[例][ruby]{
ary = ["a", "b", "c"]

ary.fetch_values(0, 2) # => ["a", "c"]
ary.fetch_values(-1, 1) # => ["d", "b"]
ary.fetch_values(0, 10) # => index 10 outside of array bounds: -3...3 (IndexError)
ary.fetch_values(0, 10) { |i| i.to_s } # => ["a", "10"]
//}

@see Array#values_at, Array#fetch...

絞り込み条件を変える

Hash#fetch_values(key, ...) -> [object] (12239.0)

引数で指定されたキーに関連づけられた値の配列を返します。

...と発生します。

//emlist[例][ruby]{
h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" }

h.fetch_values("cow", "cat") # => ["bovine", "feline"]
h.fetch_values("cow", "bird") # raises KeyError
h.fetch_values("cow", "bird") { |k| k.upcase } # => [...
..."bovine", "BIRD"]
//}

@see Hash#values_at, Hash#fetch...

Hash#fetch_values(key, ...) { |key| ... } -> [object] (12239.0)

引数で指定されたキーに関連づけられた値の配列を返します。

...と発生します。

//emlist[例][ruby]{
h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" }

h.fetch_values("cow", "cat") # => ["bovine", "feline"]
h.fetch_values("cow", "bird") # raises KeyError
h.fetch_values("cow", "bird") { |k| k.upcase } # => [...
..."bovine", "BIRD"]
//}

@see Hash#values_at, Hash#fetch...

Thread#[](name) -> object | nil (49.0)

name に対応したスレッドに固有のデータを取り出します。 name に対応するスレッド固有データがなければ nil を返し ます。

...なければ nil を返し
ます。

@param name スレッド固有データのキーを文字列か Symbol で指定します。

//emlist[例][ruby]{
[
Thread.new { Thread.current["name"] = "A" },
Thread.new { Thread.current[:name] = "B" },
Thread.new { Thread.current["name"] = "C" }
].eac...
...なる変数を返す事に注意してください。

//emlist[][ruby]{
def meth(newvalue)
begin
oldvalue = Thread.current[:name]
Thread.current[:name] = newvalue
yield
ensure
Thread.current[:name] = oldvalue
end
end
//}

この関数に与えるブロックがFiberを切り...
...コープとしては
正しく動作しません。

//emlist[][ruby]{
f = Fiber.new {
meth(1) {
Fiber.yield
}
}
meth(2) {
f.resume
}
f.resume
p Thread.current[:name]
# => nil if fiber-local
# => 2 if thread-local (The value 2 is leaked to outside of meth method.)
//}

Fiber を切り替...

Hash#[](key) -> object | nil (37.0)

key に関連づけられた値を返します。

...h#fetch または Hash#key? を使ってください。

@param key 探索するキーを指定します。

//emlist[例][ruby]{
h = {:ab => "some" , :cd => "all"}
p h[:ab] #=> "some"
p h[:ef] #=> nil

h1 = Hash.new("default value")
p h1[:non] #=> "default value"...
...h2 = Hash.new {|*arg| arg}
p h2[:non] #=> [{}, :non]
//}

@see Hash.new, Hash#fetch,Hash#values_at,Hash#key?, Hash#default, Hash#default_proc...