別のキーワード
モジュール
-
Net
:: HTTPHeader (36) - TSort (93)
キーワード
- [] (20)
-
each
_ strongly _ connected _ component (23) -
each
_ strongly _ connected _ component _ from (23) -
fetch
_ values (20) -
strongly
_ connected _ components (12) - tsort (12)
-
tsort
_ each (23)
検索結果
先頭5件
-
Array
# fetch(nth) {|nth| . . . } -> object (18128.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 (18128.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 #... -
Hash
# fetch _ values(key , . . . ) -> [object] (6133.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] (6133.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 (25.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]......}
この関数に与えるブロックが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 threa... -
Hash
# [](key) -> object | nil (19.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 (13.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 (13.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 (13.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.... -
TSort
# each _ strongly _ connected _ component _ from(node , id _ map={} , stack=[]) {|nodes| . . . } -> () (13.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....