種類
- インスタンスメソッド (2952)
- 特異メソッド (355)
- クラス (62)
- モジュール関数 (60)
ライブラリ
クラス
-
ARGF
. class (126) - Addrinfo (12)
- Array (324)
- CSV (12)
- Complex (12)
- Date (36)
- Dir (59)
- Enumerator (212)
-
Enumerator
:: ArithmeticSequence (98) -
Enumerator
:: Chain (42) -
Enumerator
:: Lazy (429) -
Enumerator
:: Yielder (30) -
Etc
:: Group (12) -
Etc
:: Passwd (12) - Float (12)
-
Gem
:: SourceIndex (12) - Hash (168)
- IO (162)
- Integer (60)
- Matrix (94)
- Numeric (81)
- Object (63)
- OpenStruct (12)
- Pathname (63)
- Prime (24)
-
Prime
:: PseudoPrimeGenerator (36) -
Psych
:: Nodes :: Node (12) -
REXML
:: Parent (48) - Range (59)
- Rational (12)
- String (80)
- StringIO (88)
- Struct (43)
- Vector (74)
-
Zlib
:: GzipReader (36)
モジュール
- Enumerable (440)
- Find (12)
- Kernel (24)
- ObjectSpace (24)
- TSort (66)
オブジェクト
- ENV (134)
-
Readline
:: HISTORY (12)
キーワード
- % (14)
- + (7)
- << (12)
- == (7)
- ArithmeticSequence (7)
- Chain (7)
- Enumerator (12)
- Lazy (12)
- Numeric (12)
- Yielder (12)
- ascend (12)
- begin (7)
- bsearch (24)
-
bsearch
_ index (10) - bytes (21)
- chain (7)
- chars (21)
- chunk (36)
-
chunk
_ while (21) - codepoints (21)
- collect (60)
- collect! (26)
- collect2 (12)
-
collect
_ concat (24) - combination (12)
- combine (8)
- compact (4)
- cycle (24)
-
delete
_ if (48) - denominator (12)
- descend (12)
- detect (12)
- downto (24)
- drop (12)
-
drop
_ while (36) - each (352)
- each2 (12)
-
each
_ byte (60) -
each
_ char (48) -
each
_ child (47) -
each
_ codepoint (48) -
each
_ cons (12) -
each
_ entry (15) -
each
_ grapheme _ cluster (8) -
each
_ index (24) -
each
_ key (24) -
each
_ line (108) -
each
_ object (24) -
each
_ pair (48) -
each
_ prime (12) -
each
_ slice (12) -
each
_ strongly _ connected _ component (22) -
each
_ strongly _ connected _ component _ from (22) -
each
_ value (24) -
each
_ with _ index (36) -
each
_ with _ object (12) - eager (6)
- end (7)
-
enum
_ for (48) -
exclude
_ end? (7) - feed (12)
- filter (42)
- filter! (21)
-
filter
_ map (12) - find (36)
-
find
_ all (24) -
find
_ index (36) - first (14)
-
flat
_ map (24) - force (12)
- foreach (60)
- grep (12)
-
grep
_ v (10) -
group
_ by (12) - gsub (24)
- gsub! (12)
- hash (7)
- index (24)
- inspect (14)
-
keep
_ if (36) - last (14)
- lazy (24)
- lines (49)
- loop (12)
- map (60)
- map! (26)
-
max
_ by (24) -
min
_ by (24) -
minmax
_ by (12) - new (38)
- next (12)
-
next
_ values (12) - partition (12)
- peek (12)
-
peek
_ values (12) - permutation (12)
- produce (6)
- reject (60)
- reject! (36)
-
repeated
_ combination (12) -
repeated
_ permutation (12) -
reverse
_ each (26) - rewind (19)
- rindex (12)
- select (72)
- select! (36)
- size (26)
-
slice
_ after (46) -
slice
_ before (60) -
slice
_ when (23) -
sort
_ by (12) -
sort
_ by! (12) - step (95)
- take (12)
-
take
_ while (48) - then (7)
- times (12)
-
to
_ enum (48) -
to
_ proc (6) -
transform
_ keys (8) -
transform
_ keys! (8) -
transform
_ values (9) -
transform
_ values! (9) -
tsort
_ each (22) - uniq (18)
- upto (24)
-
with
_ index (48) -
with
_ object (36) - yield (12)
-
yield
_ self (8) - zip (24)
検索結果
先頭5件
-
Enumerator
:: Lazy # to _ enum(method = :each , *args) {|*args| block} -> Enumerator :: Lazy (12300.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......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 のおかげで、repeat の返り値は
# もとが Enumerator のときは Enumerator に... -
Enumerator (12000.0)
-
each 以外のメソッドにも Enumerable の機能を提供するためのラッパークラスです。 また、外部イテレータとしても使えます。
...each 以外のメソッドにも Enumerable の機能を提供するためのラッパークラスです。
また、外部イテレータとしても使えます。
Enumerable モジュールは、 Module#include 先のクラスが持つ
each メソッドを元に様々なメソッドを提供し......されます。
Enumerator を介することにより String#each_byte のような
異なる名前のイテレータについても each と同様に Enumerable の機能を利用できます。
Enumerator を生成するには Enumerator.newあるいは
Object#to_enum, Object#enum_for を利用......enumerator を生成して返します。
=== 注意
外部イテレータとしての機能は Fiber を用いて実装されているため Fiber と同じ制限があります。
例えば以下のようなスレッドをまたいだ呼び出しはエラーになります。
//emlist[例][ruby... -
Enumerator
. produce(initial = nil) { |prev| . . . } -> Enumerator (9200.0) -
与えられたブロックを呼び出し続ける、停止しない Enumerator を返します。 ブロックの戻り値が、次にブロックを呼び出す時に引数として渡されます。 initial 引数が渡された場合、最初にブロックを呼び出す時にそれがブロック 呼び出しの引数として渡されます。initial が渡されなかった場合は nil が 渡されます。
...与えられたブロックを呼び出し続ける、停止しない Enumerator を返します。
ブロックの戻り値が、次にブロックを呼び出す時に引数として渡されます。
initial 引数が渡された場合、最初にブロックを呼び出す時にそれがブロ......//emlist[例][ruby]{
# 1, 2, 3, 4, ... と続く Enumerator
Enumerator.produce(1, &:succ)
# next を呼ぶたびランダムな数値を返す Enumerator
Enumerator.produce { rand(10) }
# ツリー構造の祖先ノードを列挙する Enumerator
ancestors = Enumerator.produce(node) { |prev| no......ソッドは Enumerable の各メソッドと組み合わせて使うことで、
while や until ループのような処理を実装できます。
例えば Enumerable#detect, Enumerable#slice_after, Enumerable#take_while
などと合わせて使えるでしょう。
//emlist[Enumerable のメ... -
Enumerator
:: Lazy # chunk {|elt| . . . } -> Enumerator :: Lazy (9200.0) -
Enumerable#chunk と同じですが、配列ではなく Enumerator::Lazy を返します。
...Enumerable#chunk と同じですが、配列ではなく Enumerator::Lazy を返します。
//emlist[例][ruby]{
1.step.lazy.chunk{ |n| n % 3 == 0 }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x007f8bf18118f0>:each>>
1.step.lazy.chunk{ |n| n % 3 == 0 }.take(5).force
# => [[fa......lse, [1, 2]], [true, [3]], [false, [4, 5]], [true, [6]], [false, [7, 8]]]
//}
@see Enumerable#chunk... -
Enumerator
:: Lazy # chunk(initial _ state) {|elt , state| . . . } -> Enumerator :: Lazy (9200.0) -
Enumerable#chunk と同じですが、配列ではなく Enumerator::Lazy を返します。
...Enumerable#chunk と同じですが、配列ではなく Enumerator::Lazy を返します。
//emlist[例][ruby]{
1.step.lazy.chunk{ |n| n % 3 == 0 }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x007f8bf18118f0>:each>>
1.step.lazy.chunk{ |n| n % 3 == 0 }.take(5).force
# => [[fa......lse, [1, 2]], [true, [3]], [false, [4, 5]], [true, [6]], [false, [7, 8]]]
//}
@see Enumerable#chunk... -
Enumerator
:: Lazy # chunk _ while {|elt _ before , elt _ after| . . . } -> Enumerator :: Lazy (9200.0) -
Enumerable#chunk_while と同じですが、Enumerator ではなく Enumerator::Lazy を返します。
...Enumerable#chunk_while と同じですが、Enumerator ではなく Enumerator::Lazy を返します。
@raise ArgumentError ブロックを指定しなかった場合に発生します。... -
Enumerator
:: Lazy # uniq -> Enumerator :: Lazy (9200.0) -
Enumerable#uniq と同じですが、配列ではなく Enumerator::Lazy を返します。
...Enumerable#uniq と同じですが、配列ではなく Enumerator::Lazy を返します。... -
Enumerator
:: Lazy # uniq {|item| . . . } -> Enumerator :: Lazy (9200.0) -
Enumerable#uniq と同じですが、配列ではなく Enumerator::Lazy を返します。
...Enumerable#uniq と同じですが、配列ではなく Enumerator::Lazy を返します。... -
Enumerator
# next _ values -> Array (9100.0) -
「次」のオブジェクトを配列で返します。
...「次」のオブジェクトを配列で返します。
Enumerator#next とほぼ同様の挙動をします。終端まで到達した場合は
StopIteration 例外を発生させます。
このメソッドは、
yield
と
yield nil
を区別するために使えます。
next メソッ......alues の違いを][ruby]{
o = Object.new
def o.each
yield
yield 1
yield 1, 2
yield nil
yield [1, 2]
end
e = o.to_enum
p e.next_values
p e.next_values
p e.next_values
p e.next_values
p e.next_values
e = o.to_enum
p e.next
p e.next
p e.next
p e.next
p e.next
## yield args next_values......[1] 1
# yield 1, 2 [1, 2] [1, 2]
# yield nil [nil] nil
# yield [1, 2] [[1, 2]] [1, 2]
//}
@raise StopIteration 列挙状態が既に最後へ到達しているとき
@see Enumerator#next, Enumerator#peek, Enumerator#peek_values... -
Enumerator
# peek _ values -> Array (9100.0) -
Enumerator#next_values のように「次」のオブジェクトを 配列で返しますが、列挙状態を変化させません。
...Enumerator#next_values のように「次」のオブジェクトを
配列で返しますが、列挙状態を変化させません。
Enumerator#next, Enumerator#next_values のように
現在までの列挙状態に応じて「次」のオブジェクトを返しますが、
next と異なり......numerator#next_values と同様
yield
と
yield nil
を区別するために使えます。
//emlist[例][ruby]{
o = Object.new
def o.each
yield
yield 1
yield 1, 2
end
e = o.to_enum
p e.peek_values #=> []
e.next
p e.peek_values #=> [1]
p e.peek_values #=> [1]
e.next
p e.peek_valu......es #=> [1, 2]
e.next
p e.peek_values # raises StopIteration
//}
@raise StopIteration 列挙状態が既に最後へ到達しているとき
@see Enumerator#next, Enumerator#next_values, Enumerator#peek_values...