るりまサーチ

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

別のキーワード

  1. enumerator each
  2. each enumerator
  3. enumerator with_index
  4. enumerator with_object
  5. enumerator new

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

Enumerator::Lazy#chunk {|elt| ... } -> Enumerator::Lazy (21273.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 (21273.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...

Enumerable#chunk {|elt| ... } -> Enumerator (18273.0)

要素を前から順にブロックで評価し、その結果によって 要素をチャンクに分けた(グループ化した)要素を持つ Enumerator を返します。

...)要素を持つ
Enumerator
を返します。

ブロックの評価値が同じ値が続くものを一つのチャンクとして
取り扱います。すなわち、ブロックの評価値が一つ前と
異なる所でチャンクが区切られます。

返り値の Enumerator は各チャ...
...クの要素を持つ配列のペアを各要素とします。
そのため、eachだと以下のようになります。

//emlist[][ruby]{
enum.chunk {|elt| key }.each {|key, ary| do_something }
//}

例として、整数列を連続する奇数/偶数に分ける例を見てみます。
「n.eve...
...?」の値が切り替わるところで区切られているのがわかるでしょう。

//emlist[例][ruby]{
[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5].chunk {|n|
n.even?
}.each {|even, ary|
p [even, ary]
}
# => [false, [3, 1]]
# [true, [4]]
# [false, [1, 5, 9]]
# [true, [2, 6]]
# [false...

Enumerator::Lazy#chunk_while {|elt_before, elt_after| ... } -> Enumerator::Lazy (9251.0)

Enumerable#chunk_while と同じですが、Enumerator ではなく Enumerator::Lazy を返します。

...Enumerable#chunk_while と同じですが、Enumerator ではなく Enumerator::Lazy を返します。

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

Enumerable#chunk_while {|elt_before, elt_after| ... } -> Enumerator (6261.0)

要素を前から順にブロックで評価し、その結果によって要素をチャンクに分け た(グループ化した)要素を持つEnumerator を返します。

...素を前から順にブロックで評価し、その結果によって要素をチャンクに分け
た(グループ化した)要素を持つEnumerator を返します。

隣り合う値をブロックパラメータ elt_before、elt_after に渡し、ブロックの
評価値が偽になる所...
...されます。

@return チャンクごとの配列をブロックパラメータに渡す Enumerator
を返します。eachメソッドは以下のように呼び出します。
//emlist{
enum.chunk_while { |elt_before, elt_after| bool }.each { |ary| ... }
//}
to_a や map など...
...ドも有用です。

//emlist[例][ruby]{
# 1ずつ増加する部分配列ごとに分ける。
a = [1,2,4,9,10,11,12,15,16,19,20,21]
b = a.chunk_while {|i, j| i+1 == j }
p b.to_a # => [[1, 2], [4], [9, 10, 11, 12], [15, 16], [19, 20, 21]]
c = b.map {|a| a.length < 3 ? a : "#{a.first}-#{a.la...

絞り込み条件を変える

Enumerable#slice_when {|elt_before, elt_after| bool } -> Enumerator (154.0)

要素を前から順にブロックで評価し、その結果によって要素をチャンクに分け た(グループ化した)要素を持つEnumerator を返します。

...素を前から順にブロックで評価し、その結果によって要素をチャンクに分け
た(グループ化した)要素を持つEnumerator を返します。

隣り合う値をブロックパラメータ elt_before、elt_after に渡し、ブロックの
評価値が真になる所...
...

ブロックは self の長さ - 1 回呼び出されます。

@return チャンクごとの配列をブロックパラメータに渡す Enumerator
を返します。eachメソッドは以下のように呼び出します。
//emlist{
enum.slice_when { |elt_before, elt_after| bool }...
...# (Enumerable#chunk を使って実現する事も可能)
a = [7, 5, 9, 2, 0, 7, 9, 4, 2, 0]
p a.slice_when {|i, j| i.even? != j.even? }.to_a
# => [[7, 5, 9], [2, 0], [7, 9], [4, 2, 0]]

# 段落(空行が後ろに続く非空行の文字列)ごとに分ける。
# (Enumerable#chunk で空行を無...

Enumerable#slice_before {|elt| bool } -> Enumerator (131.0)

パターンがマッチした要素、もしくはブロックが真を返した要素から 次にマッチする手前までを チャンク化(グループ化)したものを繰り返す Enumerator を 返します。

...くはブロックが真を返した要素から
次にマッチする手前までを
チャンク化(グループ化)したものを繰り返す Enumerator
返します。

パターンを渡した場合は各要素に対し === が呼び出され、
それが真になったところをチャ...
...rable#chunk_while のより簡単な例も参照)。

//emlist[][ruby]{
a = [0,2,3,4,6,7,9]
prev = a[0]
p a.slice_before {|e|
prev, prev2 = e, prev
prev2 + 1 != e
}.map {|es|
es.length <= 2 ? es.join(",") : "#{es.first}-#{es.last}"
}.join(",")
#=> "0,2-4,6,7,9"
//}


@see Enumerable#chunk, Enu...

Enumerable#slice_before(pattern) -> Enumerator (131.0)

パターンがマッチした要素、もしくはブロックが真を返した要素から 次にマッチする手前までを チャンク化(グループ化)したものを繰り返す Enumerator を 返します。

...くはブロックが真を返した要素から
次にマッチする手前までを
チャンク化(グループ化)したものを繰り返す Enumerator
返します。

パターンを渡した場合は各要素に対し === が呼び出され、
それが真になったところをチャ...
...rable#chunk_while のより簡単な例も参照)。

//emlist[][ruby]{
a = [0,2,3,4,6,7,9]
prev = a[0]
p a.slice_before {|e|
prev, prev2 = e, prev
prev2 + 1 != e
}.map {|es|
es.length <= 2 ? es.join(",") : "#{es.first}-#{es.last}"
}.join(",")
#=> "0,2-4,6,7,9"
//}


@see Enumerable#chunk, Enu...

Enumerable#slice_after {|elt| bool } -> Enumerator (125.0)

パターンがマッチした要素、もしくはブロックが真を返した要素を末尾の要素 としてチャンク化(グループ化)したものを繰り返す Enumerator を 返し ます。

...要素、もしくはブロックが真を返した要素を末尾の要素
としてチャンク化(グループ化)したものを繰り返す Enumerator を 返し
ます。

パターンを渡した場合は各要素に対し === が呼び出され、 それが真になった
ところをチャ...
..._a
#=> [["foo\n"], ["bar\\\n", "baz\n"], ["\n"], ["qux\n"]]
p e.map {|ll| ll[0...-1].map {|l| l.sub(/\\\n\z/, "") }.join + ll.last }
#=>["foo\n", "barbaz\n", "\n", "qux\n"]
//}

Enumerable#map のようなメソッドを使うこともできます。

@see Enumerable#chunk, Enumerable#slice_before...

Enumerable#slice_after(pattern) -> Enumerator (125.0)

パターンがマッチした要素、もしくはブロックが真を返した要素を末尾の要素 としてチャンク化(グループ化)したものを繰り返す Enumerator を 返し ます。

...要素、もしくはブロックが真を返した要素を末尾の要素
としてチャンク化(グループ化)したものを繰り返す Enumerator を 返し
ます。

パターンを渡した場合は各要素に対し === が呼び出され、 それが真になった
ところをチャ...
..._a
#=> [["foo\n"], ["bar\\\n", "baz\n"], ["\n"], ["qux\n"]]
p e.map {|ll| ll[0...-1].map {|l| l.sub(/\\\n\z/, "") }.join + ll.last }
#=>["foo\n", "barbaz\n", "\n", "qux\n"]
//}

Enumerable#map のようなメソッドを使うこともできます。

@see Enumerable#chunk, Enumerable#slice_before...

絞り込み条件を変える

<< 1 2 > >>