るりまサーチ

最速Rubyリファレンスマニュアル検索!
55件ヒット [1-55件を表示] (0.312秒)
トップページ > クエリ:_builtin[x] > クエリ:chunk[x] > クエリ:slice_after[x]

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

ライブラリ

モジュール

キーワード

検索結果

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

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

...できます。

//emlist[例][ruby]{
enum.slice_after(pattern).each { |ary|
# ...
}
enum.slice_after { |elt| bool }.each { |ary|
# ...
}
//}

//emlist[例][ruby]{
# 偶数要素をチャンクの末尾と見なす
[0,2,4,1,2,4,5,3,1,4,2].slice_after(&:even?).to_a
# => [[0], [2], [4], [1, 2], [4...
...クの末尾と見なす
[0,2,4,1,2,4,5,3,1,4,2].slice_after(&:odd?).to_a
# => [[0, 2, 4, 1], [2, 4, 5], [3], [1], [4, 2]]

# バックスラッシュで終わる行を継続
lines = ["foo\n", "bar\\\n", "baz\n", "\n", "qux\n"]
e = lines.slice_after(/(?<!\\)\n\z/)
p e.to_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 (26138.0)

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

...できます。

//emlist[例][ruby]{
enum.slice_after(pattern).each { |ary|
# ...
}
enum.slice_after { |elt| bool }.each { |ary|
# ...
}
//}

//emlist[例][ruby]{
# 偶数要素をチャンクの末尾と見なす
[0,2,4,1,2,4,5,3,1,4,2].slice_after(&:even?).to_a
# => [[0], [2], [4], [1, 2], [4...
...クの末尾と見なす
[0,2,4,1,2,4,5,3,1,4,2].slice_after(&:odd?).to_a
# => [[0, 2, 4, 1], [2, 4, 5], [3], [1], [4, 2]]

# バックスラッシュで終わる行を継続
lines = ["foo\n", "bar\\\n", "baz\n", "\n", "qux\n"]
e = lines.slice_after(/(?<!\\)\n\z/)
p e.to_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_before {|elt| bool } -> Enumerator (8018.0)

パターンがマッチした要素、もしくはブロックが真を返した要素から 次にマッチする手前までを チャンク化(グループ化)したものを繰り返す 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...
...merable#slice_after...

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

パターンがマッチした要素、もしくはブロックが真を返した要素から 次にマッチする手前までを チャンク化(グループ化)したものを繰り返す 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...
...merable#slice_after...

Enumerator::Lazy (8018.0)

map や select などのメソッドの遅延評価版を提供するためのクラス。

...* map/collect
* flat_map/collect_concat
* select/find_all
* reject
* grep
* take, take_while
* drop, drop_while
* slice_before, slice_after, slice_when
* chunk
* zip (※互換性のため、ブロックを渡さないケースのみlazy)

Lazyオブジェクトは、Enumerable#lazyメソ...
...llect
* flat_map/collect_concat
* select/find_all
* reject
* grep, grep_v
* take, take_while
* drop, drop_while
* slice_before, slice_after, slice_when
* chunk
* zip (※互換性のため、ブロックを渡さないケースのみlazy)

Lazyオブジェクトは、Enumerable#lazyメソ...
...t
* flat_map/collect_concat
* select/find_all
* reject
* grep, grep_v
* take, take_while
* drop, drop_while
* slice_before, slice_after, slice_when
* chunk, chunk_while
* uniq
* zip (※互換性のため、ブロックを渡さないケースのみlazy)

Lazyオブジェクトは、Enumer...
...collect_concat
* filter_map
* select/find_all
* reject
* grep, grep_v
* take, take_while
* drop, drop_while
* slice_before, slice_after, slice_when
* chunk, chunk_while
* uniq
* zip (※互換性のため、ブロックを渡さないケースのみlazy)

Lazyオブジェクトは、Enumer...
...collect_concat
* filter_map
* select/find_all
* reject
* grep, grep_v
* take, take_while
* drop, drop_while
* slice_before, slice_after, slice_when
* chunk, chunk_while
* uniq
* compact
* zip (※互換性のため、ブロックを渡さないケースのみlazy)

Lazyオブジェクト...

絞り込み条件を変える