るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

モジュール

検索結果

<< < 1 2 3 > >>

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

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

...価した結果を返します。

@
param nth 取得したい要素のインデックスを整数で指定します。
整数以外のオブジェクトを指定した場合は to_int メソッドによる
暗黙の型変換を試みます。

@
param ifnone 要素が存在し...
...なかった場合に返すべき値を指定します。

@
raise TypeError 引数 nth に整数以外の(暗黙の型変換が行えない)オブジェ
クトを指定した場合に発生します。

@
raise IndexError 引数 ifnone もブロックも指定しておらず、 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 (18258.0)

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

...価した結果を返します。

@
param nth 取得したい要素のインデックスを整数で指定します。
整数以外のオブジェクトを指定した場合は to_int メソッドによる
暗黙の型変換を試みます。

@
param ifnone 要素が存在し...
...なかった場合に返すべき値を指定します。

@
raise TypeError 引数 nth に整数以外の(暗黙の型変換が行えない)オブジェ
クトを指定した場合に発生します。

@
raise IndexError 引数 ifnone もブロックも指定しておらず、 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 (6269.0)

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

...します。

@
param indexes 取得したい要素のインデックスを指定します。

@
raise IndexError ブロックが与えられてない時に、範囲外のインデックスを引数で指定すると発生します。

//emlist[例][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 (6269.0)

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

...します。

@
param indexes 取得したい要素のインデックスを指定します。

@
raise IndexError ブロックが与えられてない時に、範囲外のインデックスを引数で指定すると発生します。

//emlist[例][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] (6257.0)

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

...ません)。

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

@
raise KeyError ブロックが与えられてない時にキーの探索に失敗すると発生します。

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

h.fetch_values("cow", "ca...
...t") # => ["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] (6257.0)

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

...ません)。

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

@
raise KeyError ブロックが与えられてない時にキーの探索に失敗すると発生します。

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

h.fetch_values("cow", "ca...
...t") # => ["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 (167.0)

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

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

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

//emlist[例][ruby]{
[
Thread.new { Thread.current["name"] = "A" },
Thread.new { Thread.current[:name] = "...
...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 (137.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_from(node, id_map={}, stack=[]) -> Enumerator (131.0)

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

...ort_each_node を呼びません。

@
param 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.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| ...} -> () (131.0)

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

...ort_each_node を呼びません。

@
param 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.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#tsort -> Array (131.0)

頂点をトポロジカルソートして得られる配列を返します。 この配列は子から親に向かってソートされています。 すなわち、最初の要素は子を持たず、最後の要素は親を持ちません。

...後の要素は親を持ちません。

@
raise TSort::Cyclic 閉路が存在するとき、発生します。

//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

sorted...
...= {1=>[2, 3], 2=>[3], 3=>[], 4=>[]}.tsort
p sorted #=> [3, 2, 1, 4]
//}

@
see TSort.tsort...

TSort#tsort_each -> Enumerator (131.0)

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

...外 TSort::Cyclic を起こします。

@
raise TSort::Cyclic 閉路が存在するとき、発生します.

//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, 3], 2=>[3], 3=>[], 4=>[]}

non_sort.tsort_each {|node|
non_sort.tsort_each_child(node){|child|
printf("%d -> %d\n", node, child)
}
}

# 出力
#=> 2 -> 3
#=> 1 -> 2
#=> 1 -> 3
//}

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