るりまサーチ

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

別のキーワード

  1. _builtin slice
  2. _builtin slice!
  3. string slice
  4. string slice!
  5. _builtin slice_before

ライブラリ

モジュール

検索結果

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

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

...素をチャンクの先頭と見なす
[0,2,4,1,2,4,5,3,1,4,2].slice_before(&:even?).to_a
# => [[0], [2], [4, 1], [2], [4, 5, 3, 1], [4], [2]]

# 奇数要素をチャンクの先頭と見なす
[0,2,4,1,2,4,5,3,1,4,2].slice_before(&:odd?).to_a
# => [[0, 2, 4], [1, 2, 4], [5], [3], [1, 4, 2]]

# Ch...
...angeLog のエントリーを順に取る
open("ChangeLog") {|f|
f.slice_before(/\A\S/).each {|e| pp e}
}

# 上と同じだが、パターンでなくブロックを使う
open("ChangeLog") {|f|
f.slice_before {|line| /\A\S/ === line }.each {|e| pp e}
}

# "svn proplist -R" の結果を分割...
...erable#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, En...

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

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

...素をチャンクの先頭と見なす
[0,2,4,1,2,4,5,3,1,4,2].slice_before(&:even?).to_a
# => [[0], [2], [4, 1], [2], [4, 5, 3, 1], [4], [2]]

# 奇数要素をチャンクの先頭と見なす
[0,2,4,1,2,4,5,3,1,4,2].slice_before(&:odd?).to_a
# => [[0, 2, 4], [1, 2, 4], [5], [3], [1, 4, 2]]

# Ch...
...angeLog のエントリーを順に取る
open("ChangeLog") {|f|
f.slice_before(/\A\S/).each {|e| pp e}
}

# 上と同じだが、パターンでなくブロックを使う
open("ChangeLog") {|f|
f.slice_before {|line| /\A\S/ === line }.each {|e| pp e}
}

# "svn proplist -R" の結果を分割...
...erable#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, En...

NEWS for Ruby 2.2.0 (12.0)

NEWS for Ruby 2.2.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...ジェクトを返します。

=== 組み込みクラスの互換性 (機能追加とバグ修正を除く)

* Enumerable
* Enumerable#slice_before の状態管理は非推奨になりました
* Enumerable#chunk の状態管理は非推奨になりました

* GC
* 非互換: GC.st...
...as a
block, and the number of yielded arguments does not match the formal
arguments of the lambda, if just an array is yielded and its length
matches.

* Process
* Process.spawn のようなプロセスを起動するようなメソッドは [:out, :err]
からリダ...