るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

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

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

...ャンクは配列として表現されます。

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

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

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

# 上と同じだが、パターンでなくブロックを使う
open("ChangeLog") {|f|
f.slice_before {|...
...を分割する
# これは一要素が複数行にまたがっている

IO.popen([{"LC_ALL"=>"C"}, "svn", "proplist", "-R"]) {|f|
f.lines.slice_before(/\AProp/).each {|lines| p lines }
}
#=> ["Properties on '.':\n", " svn:ignore\n", " svk:merge\n"]
# ["Properties on 'goruby.c':\n", " svn:eo...

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

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

...ャンクは配列として表現されます。

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

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

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

# 上と同じだが、パターンでなくブロックを使う
open("ChangeLog") {|f|
f.slice_before {|...
...を分割する
# これは一要素が複数行にまたがっている

IO.popen([{"LC_ALL"=>"C"}, "svn", "proplist", "-R"]) {|f|
f.lines.slice_before(/\AProp/).each {|lines| p lines }
}
#=> ["Properties on '.':\n", " svn:ignore\n", " svk:merge\n"]
# ["Properties on 'goruby.c':\n", " svn:eo...

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

パターンがマッチした要素、もしくはブロックが真を返した要素を末尾の要素 としてチャンク化(グループ化)したものを繰り返す 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 (21024.0)

パターンがマッチした要素、もしくはブロックが真を返した要素を末尾の要素 としてチャンク化(グループ化)したものを繰り返す 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#each_entry -> Enumerator (21018.0)

ブロックを各要素に一度ずつ適用します。

...配列として渡されます。

//emlist[例][ruby]{
class Foo
include Enumerable
def each
yield 1
yield 1,2
end
end
Foo.new.each_entry{|o| print o, " -- "}
# => 1 -- [1, 2] --
//}

ブロックを省略した場合は Enumerator が返されます。

@see Enumerable#slice_before...

絞り込み条件を変える

Enumerable#each_entry {|obj| block} -> self (21018.0)

ブロックを各要素に一度ずつ適用します。

...配列として渡されます。

//emlist[例][ruby]{
class Foo
include Enumerable
def each
yield 1
yield 1,2
end
end
Foo.new.each_entry{|o| print o, " -- "}
# => 1 -- [1, 2] --
//}

ブロックを省略した場合は Enumerator が返されます。

@see Enumerable#slice_before...

Enumerator::Lazy#slice_before {|elt| bool } -> Enumerator::Lazy (18159.0)

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

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

//emlist[例][ruby]{
1.step.lazy.slice_before { |e| e.even? }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x00007f9f31844ce8>:each>>

1.step.lazy.slice_before { |e| e % 3 == 0 }.t...
...ake(5).force
# => [[1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11], [12, 13, 14]]
//}

@see Enumerable#slice_before...

Enumerator::Lazy#slice_before(initial_state) {|elt, state| bool } -> Enumerator::Lazy (18159.0)

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

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

//emlist[例][ruby]{
1.step.lazy.slice_before { |e| e.even? }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x00007f9f31844ce8>:each>>

1.step.lazy.slice_before { |e| e % 3 == 0 }.t...
...ake(5).force
# => [[1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11], [12, 13, 14]]
//}

@see Enumerable#slice_before...

Enumerator::Lazy#slice_before(pattern) -> Enumerator::Lazy (18159.0)

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

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

//emlist[例][ruby]{
1.step.lazy.slice_before { |e| e.even? }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x00007f9f31844ce8>:each>>

1.step.lazy.slice_before { |e| e % 3 == 0 }.t...
...ake(5).force
# => [[1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11], [12, 13, 14]]
//}

@see Enumerable#slice_before...

NEWS for Ruby 2.2.0 (66.0)

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

...* 追加: Binding#receiver

* Dir
* 追加: Dir#fileno

* Enumerable
* 追加: Enumerable#slice_after
* 追加: Enumerable#slice_when
* 拡張: Enumerable#min, Enumerable#min_by, Enumerable#max, Enumerable#max_by
は複数の値を返すためのオプションをサ...
...返します。

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

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

* GC
* 非互換: GC.stat のエント...

絞り込み条件を変える

<< 1 2 > >>