るりまサーチ

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

別のキーワード

  1. _builtin to_a
  2. matrix to_a
  3. to_a
  4. dbm to_a
  5. argf.class to_a

ライブラリ

クラス

モジュール

検索結果

<< 1 2 3 ... > >>

Matrix#each(which = :all) -> Enumerator (24333.0)

行列の各要素を引数としてブロックを呼び出します。

...bol を指定することで
引数として使われる要素を限定することができます。
* :all - すべての要素(デフォルト)
* :diagonal - 対角要素
* :off_diagonal 対角要素以外
* :lower 対角成分とそれより下側の部分
* :upper対角成分とそれ...
...上側

ブロックを省略した場合、 Enumerator を返します。

//emlist[例][ruby]{
require 'matrix'
Matrix[ [1,2], [3,4] ].each { |e| puts e }
# => prints the numbers 1 to 4
Matrix[ [1,2], [3,4] ].each(:strict_lower).to_a # => [3]
//}

@param which どの要素に対してブロック...
...を呼び出すのかを Symbol で指定します
@see Matrix#each_with_index, Matrix#map...

Matrix#map(which = :all) -> Enumerator (21333.0)

行列の各要素に対してブロックの適用を繰り返した結果を、要素として持つ行列を生成します。

...Enumerator を返します。

@param which which に以下の Symbol を指定することで、
引数として使われる要素を限定できます。
デフォルトは、:all (全ての要素)です。
指定できる Symbol の詳細は、 Matrix#ea...
...ch の項目を参照して下さい。

//emlist[例][ruby]{
require 'matrix'

m = Matrix[[1, 2], [3, 4]]
p m.map { |x| x + 100 } # => Matrix[[101, 102], [103, 104]]
p m.map(:diagonal) { |x| x * 10 } # => Matrix[[10, 2], [3, 40]]
//}

@see Matrix#each, Matrix#map!...

Matrix#map -> Enumerator (21315.0)

行列の各要素に対してブロックの適用を繰り返した結果を、要素として持つ行列を生成します。

...適用を繰り返した結果を、要素として持つ行列を生成します。

ブロックがない場合、 Enumerator を返します。


//emlist[例][ruby]{
require 'matrix'

m = Matrix[[1, 2], [3, 4]]
p m.map { |x| x + 100 } # => Matrix[[101, 102], [103, 104]]
//}

@see Matrix#each...

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

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

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

返す値は規定されていません。

each
_strongly_connected_component_from は
tsort_each_node を呼びません。

@param node ノードを指定します。

//emlist[例 到達可能なノードを表示...
...class Hash
include TSort
a
lias tsort_each_node each_key
def tsort_each_child(node, &block)
fetch(node).each(&block)
end
end

n
on_sort = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}

n
on_sort.each_strongly_connected_component{|nodes|
p nodes
n
odes.each {|node|
n
on_sort.each_strongly_connec...
...ted_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| ...} -> () (18571.0)

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

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

返す値は規定されていません。

each
_strongly_connected_component_from は
tsort_each_node を呼びません。

@param node ノードを指定します。

//emlist[例 到達可能なノードを表示...
...class Hash
include TSort
a
lias tsort_each_node each_key
def tsort_each_child(node, &block)
fetch(node).each(&block)
end
end

n
on_sort = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}

n
on_sort.each_strongly_connected_component{|nodes|
p nodes
n
odes.each {|node|
n
on_sort.each_strongly_connec...
...ted_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...

絞り込み条件を変える

Enumerator::Lazy#flat_map {|item| ... } -> Enumerator::Lazy (15450.0)

ブロックの実行結果をひとつに繋げたものに対してイテレートするような Enumerator::Lazy のインスタンスを返します。

...とつに繋げたものに対してイテレートするような
Enumerator::Lazy のインスタンスを返します。

//emlist[][ruby]{
["foo", "bar"].lazy.flat_map {|i| i.each_char.lazy}.force
#=> ["f", "o", "o", "b", "a", "r"]
//}

ブロックの返した値 x は、以下の場合にの...
...か、to_ary メソッドを持つとき
* x が each および force メソッドを持つ (例:Enumerator::Lazy) とき

それ以外のときは、x は分解されず、そのままの値として使われます。

//emlist[][ruby]{
[{a:1}, {b:2}].lazy.flat_map {|i| i}.force
#=> [{:a=>1}, {:...
...b=>2}]
//}

@raise ArgumentError ブロックを指定しなかった場合に発生します。

@see Enumerable#flat_map...

Enumerator::Lazy#collect_concat {|item| ... } -> Enumerator::Lazy (15350.0)

ブロックの実行結果をひとつに繋げたものに対してイテレートするような Enumerator::Lazy のインスタンスを返します。

...とつに繋げたものに対してイテレートするような
Enumerator::Lazy のインスタンスを返します。

//emlist[][ruby]{
["foo", "bar"].lazy.flat_map {|i| i.each_char.lazy}.force
#=> ["f", "o", "o", "b", "a", "r"]
//}

ブロックの返した値 x は、以下の場合にの...
...か、to_ary メソッドを持つとき
* x が each および force メソッドを持つ (例:Enumerator::Lazy) とき

それ以外のときは、x は分解されず、そのままの値として使われます。

//emlist[][ruby]{
[{a:1}, {b:2}].lazy.flat_map {|i| i}.force
#=> [{:a=>1}, {:...
...b=>2}]
//}

@raise ArgumentError ブロックを指定しなかった場合に発生します。

@see Enumerable#flat_map...

Enumerator::Lazy#enum_for(method = :each, *args) -> Enumerator::Lazy (12477.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...Object#to_enum と同じですが、Enumerator::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が...
...に、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。

//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0
if...
...ock_given?
each
do |*val|
n
.times { yield *val }
end
else
to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

# Lazy#to_enum の...

Enumerator::Lazy#enum_for(method = :each, *args) {|*args| block} -> Enumerator::Lazy (12477.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...Object#to_enum と同じですが、Enumerator::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が...
...に、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。

//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0
if...
...ock_given?
each
do |*val|
n
.times { yield *val }
end
else
to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

# Lazy#to_enum の...

Enumerator::Lazy#to_enum(method = :each, *args) -> Enumerator::Lazy (12477.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...Object#to_enum と同じですが、Enumerator::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が...
...に、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。

//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0
if...
...ock_given?
each
do |*val|
n
.times { yield *val }
end
else
to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

# Lazy#to_enum の...

絞り込み条件を変える

Enumerator::Lazy#to_enum(method = :each, *args) {|*args| block} -> Enumerator::Lazy (12477.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...Object#to_enum と同じですが、Enumerator::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が...
...に、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。

//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0
if...
...ock_given?
each
do |*val|
n
.times { yield *val }
end
else
to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

# Lazy#to_enum の...
<< 1 2 3 ... > >>