るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

モジュール

検索結果

<< < 1 2 3 > >>

Array#fetch(nth) {|nth| ... } -> object (18228.0)

nth 番目の要素を返します。

...素も存在しなかった場合に発生します。

//emlist[例][ruby]{
a = [1, 2, 3, 4, 5]
begin
p a.fetch(10)
rescue IndexError => err
puts err #=> index 10 out of array
end

p a.fetch(10, 999) #=> 999

result = a.fetch(10){|nth|
print "#{nth} はありません。\n"
999
}
p result #...

Array#fetch(nth, ifnone) -> object (18228.0)

nth 番目の要素を返します。

...素も存在しなかった場合に発生します。

//emlist[例][ruby]{
a = [1, 2, 3, 4, 5]
begin
p a.fetch(10)
rescue IndexError => err
puts err #=> index 10 out of array
end

p a.fetch(10, 999) #=> 999

result = a.fetch(10){|nth|
print "#{nth} はありません。\n"
999
}
p result #...

Array#fetch_values(*indexes) -> Array (6245.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 (6245.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] (6233.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] (6233.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 (137.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...
...ead#[]= を用いたスレッド固有の変数は
Fiber を切り替えると異なる変数を返す事に注意してください。

//emlist[][ruby]{
def meth(newvalue)
begin
oldvalue = Thread.current[:name]
Thread.current[:name] = newvalue
yield
ensure
Thread.current[:name]...
...的スコープとしては
正しく動作しません。

//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 (119.0)

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

...デフォルト値と値としての nil を区別する必要が
ある場合は Hash#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...

TSort#each_strongly_connected_component -> Enumerator (113.0)

TSort#strongly_connected_components メソッドのイテレータ版です。 obj.each_strongly_connected_component は obj.strongly_connected_components.each に似ていますが、 ブロックの評価中に obj が変更された場合は予期しない結果になる ことがあります。

...each_strongly_connected_component は nil を返します。

//emlist[使用例][ruby]{
require 'tsort'

class Hash
include TSort
alias tsort_each_node each_key
def tsort_each_child(node, &block)
fetch
(node).each(&block)
end
end

non_sort = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}

non_sort...

TSort#each_strongly_connected_component {|nodes| ...} -> nil (113.0)

TSort#strongly_connected_components メソッドのイテレータ版です。 obj.each_strongly_connected_component は obj.strongly_connected_components.each に似ていますが、 ブロックの評価中に obj が変更された場合は予期しない結果になる ことがあります。

...each_strongly_connected_component は nil を返します。

//emlist[使用例][ruby]{
require 'tsort'

class Hash
include TSort
alias tsort_each_node each_key
def tsort_each_child(node, &block)
fetch
(node).each(&block)
end
end

non_sort = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}

non_sort...

絞り込み条件を変える

TSort#each_strongly_connected_component_from(node, id_map={}, stack=[]) -> Enumerator (113.0)

node から到達可能な強連結成分についてのイテレータです。

...ードを指定します。

//emlist[例 到達可能なノードを表示する][ruby]{
require 'tsort'

class Hash
include TSort
alias tsort_each_node each_key
def tsort_each_child(node, &block)
fetch
(node).each(&block)
end
end

non_sort = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}

non_sort....
...sort.each_strongly_connected_component_from(node){|ns|
printf("%s -> %s\n", node, ns.join(","))
}
}
}

#出力
#=> [4]
#=> 4 -> 4
#=> [2, 3]
#=> 2 -> 4
#=> 2 -> 2,3
#=> 3 -> 4
#=> 3 -> 3,2
#=> [1]
#=> 1 -> 4
#=> 1 -> 2,3
#=> 1 -> 1
//}

@see TSort.each_strongly_connected_component_from...

TSort#each_strongly_connected_component_from(node, id_map={}, stack=[]) {|nodes| ...} -> () (113.0)

node から到達可能な強連結成分についてのイテレータです。

...ードを指定します。

//emlist[例 到達可能なノードを表示する][ruby]{
require 'tsort'

class Hash
include TSort
alias tsort_each_node each_key
def tsort_each_child(node, &block)
fetch
(node).each(&block)
end
end

non_sort = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}

non_sort....
...sort.each_strongly_connected_component_from(node){|ns|
printf("%s -> %s\n", node, ns.join(","))
}
}
}

#出力
#=> [4]
#=> 4 -> 4
#=> [2, 3]
#=> 2 -> 4
#=> 2 -> 2,3
#=> 3 -> 4
#=> 3 -> 3,2
#=> [1]
#=> 1 -> 4
#=> 1 -> 2,3
#=> 1 -> 1
//}

@see TSort.each_strongly_connected_component_from...
<< < 1 2 3 > >>