種類
- インスタンスメソッド (110)
- 特異メソッド (11)
クラス
- Array (22)
-
Enumerator
:: Lazy (44) - Object (11)
- PP (11)
モジュール
- Enumerable (33)
キーワード
- lazy (11)
-
pretty
_ print _ cycle (11) -
sharing
_ detection (11) -
take
_ while (22) - zip (22)
検索結果
先頭5件
-
Enumerable
# cycle(n=nil) -> Enumerator (30414.0) -
Enumerable オブジェクトの各要素を n 回 or 無限回(n=nil)繰り返し ブロックを呼びだします。
...numerable オブジェクトの各要素を n 回 or 無限回(n=nil)繰り返し
ブロックを呼びだします。
n に 0 もしくは負の値を渡した場合は何もしません。
繰り返しが最後まで終了した場合(つまりbreakなどで中断しなかった場合)
は nil......め、
一度 Enumerable の終端に到達した後に自分自身を変更しても
このメソッドの動作に影響を与えません。
//emlist[例][ruby]{
a = ["a", "b", "c"]
a.cycle {|x| puts x } # print, a, b, c, a, b, c,.. forever.
a.cycle(2) {|x| puts x } # print, a, b, c, a, b, c.......//}
ブロックを省略した場合は、n 回 or 無限回 enum の各要素を
繰り返す Enumerator を返します。
@return ブロックを指定しなかった場合は、Enumerator を返します。
レシーバが空の場合は nil を返します。... -
Enumerable
# cycle(n=nil) {|obj| . . . } -> object | nil (30314.0) -
Enumerable オブジェクトの各要素を n 回 or 無限回(n=nil)繰り返し ブロックを呼びだします。
...numerable オブジェクトの各要素を n 回 or 無限回(n=nil)繰り返し
ブロックを呼びだします。
n に 0 もしくは負の値を渡した場合は何もしません。
繰り返しが最後まで終了した場合(つまりbreakなどで中断しなかった場合)
は nil......め、
一度 Enumerable の終端に到達した後に自分自身を変更しても
このメソッドの動作に影響を与えません。
//emlist[例][ruby]{
a = ["a", "b", "c"]
a.cycle {|x| puts x } # print, a, b, c, a, b, c,.. forever.
a.cycle(2) {|x| puts x } # print, a, b, c, a, b, c.......//}
ブロックを省略した場合は、n 回 or 無限回 enum の各要素を
繰り返す Enumerator を返します。
@return ブロックを指定しなかった場合は、Enumerator を返します。
レシーバが空の場合は nil を返します。... -
Array
# cycle(n=nil) -> Enumerator (27408.0) -
配列の全要素を n 回(nilの場合は無限に)繰り返しブロックを呼びだします。
...配列の全要素を n 回(nilの場合は無限に)繰り返しブロックを呼びだします。
ブロックを省略した場合は Enumerator を返します。
@param n 繰り返したい回数を整数で指定します。
整数以外のオブジェクトを指定した場合......黙の型変換を試みます。
@raise TypeError 引数に整数以外の(暗黙の型変換が行えない)オブジェクトを
指定した場合に発生します。
//emlist[例][ruby]{
a = ["a", "b", "c"]
a.cycle {|x| puts x } # print, a, b, c, a, b, c,.. forever.
//}... -
Array
# cycle(n=nil) {|obj| block } -> nil (27308.0) -
配列の全要素を n 回(nilの場合は無限に)繰り返しブロックを呼びだします。
...配列の全要素を n 回(nilの場合は無限に)繰り返しブロックを呼びだします。
ブロックを省略した場合は Enumerator を返します。
@param n 繰り返したい回数を整数で指定します。
整数以外のオブジェクトを指定した場合......黙の型変換を試みます。
@raise TypeError 引数に整数以外の(暗黙の型変換が行えない)オブジェクトを
指定した場合に発生します。
//emlist[例][ruby]{
a = ["a", "b", "c"]
a.cycle {|x| puts x } # print, a, b, c, a, b, c,.. forever.
//}... -
Object
# pretty _ print _ cycle(pp) -> () (18407.0) -
プリティプリント時にオブジェクトの循環参照が検出された場合、 Object#pretty_print の代わりに呼ばれるメソッドです。
...t#pretty_print の代わりに呼ばれるメソッドです。
あるクラスの pp の出力をカスタマイズしたい場合は、
このメソッドも再定義する必要があります。
@param pp PP オブジェクトです。
//emlist[][ruby]{
class Array
def pretty_print_cycle(q)......q.text(empty? ? '[]' : '[...]')
end
end
//}
@see Object#pretty_print... -
Enumerable
# lazy -> Enumerator :: Lazy (9406.0) -
自身を lazy な Enumerator に変換したものを返します。
...を lazy な Enumerator に変換したものを返します。
この Enumerator は、以下のメソッドが遅延評価を行う (つまり、配列ではな
くEnumeratorを返す) ように再定義されています。
* map/collect
* flat_map/collect_concat
* select/find_all
* reject......* grep
* take, take_while
* drop, drop_while
* zip (※一貫性のため、ブロックを渡さないケースのみlazy)
* cycle (※一貫性のため、ブロックを渡さないケースのみlazy)
以下はピタゴラス数 (a**2 + b**2 = c**2 を満たす自然数 a, b, c の組) を......//emlist[例][ruby]{
def pythagorean_triples
(1..Float::INFINITY).lazy.flat_map {|z|
(1..z).flat_map {|x|
(x..z).select {|y|
x**2 + y**2 == z**2
}.map {|y|
[x, y, z]
}
}
}
end
# 最初の10個のピタゴラス数を表示する
p pythagorean_triples.ta... -
Enumerator
:: Lazy # take _ while -> Enumerator :: Lazy (9318.0) -
Enumerable#take_while と同じですが、配列ではなくEnumerator::Lazy を返します。
...Enumerable#take_while と同じですが、配列ではなくEnumerator::Lazy を返します。
//emlist[例][ruby]{
1.step.lazy.zip(('a'..'z').cycle).take_while { |e| e.first < 100_000 }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:zip(#<Enumerator: "a"........"z":cycle>)>:take_while>
1.step.lazy.zip(('a'..'z').cycle).take_while { |e| e.first < 100_000 }.force.last(5)
# => [[99995, "y"], [99996, "z"], [99997, "a"], [99998, "b"], [99999, "c"]]
//}
@see Enumerable#take_while... -
Enumerator
:: Lazy # take _ while {|item| . . . } -> Enumerator :: Lazy (9318.0) -
Enumerable#take_while と同じですが、配列ではなくEnumerator::Lazy を返します。
...Enumerable#take_while と同じですが、配列ではなくEnumerator::Lazy を返します。
//emlist[例][ruby]{
1.step.lazy.zip(('a'..'z').cycle).take_while { |e| e.first < 100_000 }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:zip(#<Enumerator: "a"........"z":cycle>)>:take_while>
1.step.lazy.zip(('a'..'z').cycle).take_while { |e| e.first < 100_000 }.force.last(5)
# => [[99995, "y"], [99996, "z"], [99997, "a"], [99998, "b"], [99999, "c"]]
//}
@see Enumerable#take_while... -
Enumerator
:: Lazy # zip(*lists) -> Enumerator :: Lazy (6318.0) -
Enumerable#zip と同じですが、配列ではなくEnumerator::Lazy を返します。
...Enumerable#zip と同じですが、配列ではなくEnumerator::Lazy を返します。
ただし一貫性のため、ブロック付きで呼び出した場合は Enumerable#zip と
同じ挙動になります。
//emlist[例][ruby]{
1.step.lazy.zip(('a'..'z').cycle)
# => #<Enumerator::Lazy: #......<Enumerator::Lazy: #<Enumerator: 1:step>>:zip(#<Enumerator: "a".."z":cycle>)>
1.step.lazy.zip(('a'..'z').cycle).take(30).force.last(6)
# => [[25, "y"], [26, "z"], [27, "a"], [28, "b"], [29, "c"], [30, "d"]]
//}
@see Enumerable#zip... -
PP
. sharing _ detection -> bool (6316.0) -
共有検出フラグを表すアクセサです。 デフォルトは false です。true である場合、 PP.pp は一度出力したオブジェクトを再び出力する時 Object#pretty_print_cycle を使います。
...デフォルトは false です。true である場合、
PP.pp は一度出力したオブジェクトを再び出力する時
Object#pretty_print_cycle を使います。
@param boolean 共有検出フラグを true か false で指定します。
//emlist[][ruby]{
require 'pp'
b = [1, 2, 3]
a......= [b, b]
pp a #=> [[1, 2, 3], [1, 2, 3]]
PP.sharing_detection = true
pp a #=> [[1, 2, 3], [...]]
//}...