るりまサーチ

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

別のキーワード

  1. util u
  2. erb u
  3. matrix u
  4. _builtin koi8_u
  5. encoding koi8_u

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

Enumerator::Lazy#grep(pattern) {|item| ... } -> Enumerator::Lazy (21254.0)

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

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

//emlist[例][ruby]{
(100..Float::INFINITY).lazy.map(&:to_s).grep(/\A(\d)\1+\z/)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: 100..Infinity>:map>:grep(/\A(\d)\1+\z/)>
(100..Float::INFINIT...
...Y).lazy.map(&:to_s).grep(/\A(\d)\1+\z/).take(10).force
# => ["111", "222", "333", "444", "555", "666", "777", "888", "999", "1111"]
//}

@see Enumerable#grep...
...Y).lazy.map(&:to_s).grep(/\A(\d)\1+\z/).take(10).force
# => ["111", "222", "333", "444", "555", "666", "777", "888", "999", "1111"]
//}

@see Enumerable#grep, Enumerable#grep_v, Enumerator::Lazy#grep_v...

Enumerable#grep(pattern) -> [object] (21127.0)

pattern === item が成立する要素を全て含んだ配列を返します。

...返します。

@param pattern 「===」メソッドを持つオブジェクトを指定します。

//emlist[例][ruby]{
['aa', 'bb', 'cc', 'dd', 'ee'].grep(/[bc]/) # => ["bb", "cc"]

Array.instance_methods.grep(/gr/) # => [:grep, :group_by]
//}

@see Enumerable#select
@see Enumerable#grep_v...

Enumerable#grep(pattern) {|item| ... } -> [object] (21127.0)

pattern === item が成立する要素を全て含んだ配列を返します。

...返します。

@param pattern 「===」メソッドを持つオブジェクトを指定します。

//emlist[例][ruby]{
['aa', 'bb', 'cc', 'dd', 'ee'].grep(/[bc]/) # => ["bb", "cc"]

Array.instance_methods.grep(/gr/) # => [:grep, :group_by]
//}

@see Enumerable#select
@see Enumerable#grep_v...

Enumerator::Lazy#grep_v(pattern) {|item| ... } -> Enumerator::Lazy (9254.0)

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

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

//emlist[例][ruby]{
(100..Float::INFINITY).lazy.map(&:to_s).grep_v(/(\d).*\1/)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: 100..Infinity>:map>:grep_v(/(\d).*\1/)>
(100..Float::INFINIT...
...Y).lazy.map(&:to_s).grep_v(/(\d).*\1/).take(15).force
# => ["102", "103", "104", "105", "106", "107", "108", "109", "120", "123", "124", "125", "126", "127", "128"]
//}

@see Enumerable#grep_v, Enumerable#grep, Enumerator::Lazy#grep...

Enumerable#grep_v(pattern) -> [object] (9137.0)

Enumerable#grep のマッチの条件を逆にして、pattern === item が成立 しない要素を全て含んだ配列を返します。

...Enumerable#grep のマッチの条件を逆にして、pattern === item が成立
しない要素を全て含んだ配列を返します。

@param pattern 「===」メソッドを持つオブジェクトを指定します。

//emlist[例][ruby]{
(1..10).grep_v 2..5 # => [1, 6, 7, 8, 9, 10]
res...
...=(1..10).grep_v(2..5) { |v| v * 2 }
res # => [2, 12, 14, 16, 18, 20]
//}

@see Enumerable#grep
@see Enumerable#reject...

絞り込み条件を変える

Enumerable#grep_v(pattern) { |item| ... } -> [object] (9137.0)

Enumerable#grep のマッチの条件を逆にして、pattern === item が成立 しない要素を全て含んだ配列を返します。

...Enumerable#grep のマッチの条件を逆にして、pattern === item が成立
しない要素を全て含んだ配列を返します。

@param pattern 「===」メソッドを持つオブジェクトを指定します。

//emlist[例][ruby]{
(1..10).grep_v 2..5 # => [1, 6, 7, 8, 9, 10]
res...
...=(1..10).grep_v(2..5) { |v| v * 2 }
res # => [2, 12, 14, 16, 18, 20]
//}

@see Enumerable#grep
@see Enumerable#reject...

Rake::FileList#egrep(pattern) {|filename, count, line| ... } (6217.0)

与えられたパターンをファイルリストから grep のように検索します。

...与えられたパターンをファイルリストから grep のように検索します。

ブロックが与えられた場合は、マッチした行の情報 (ファイル名、行番号、マッチした行) が
ブロックに渡されてブロックが評価されます。ブロックが...
...mlist[][ruby]{
# Rakefile での記載例とする

IO.write("sample1", "line1\nline2\nline3\n")
IO.write("sample2", "line1\nline2\nline3\nline4\n")

task default: :test_rake_app
task :test_rake_app do

file_list = FileList.new('sample*')
file_list.egrep(/line/) # => 7

file_list.egrep(/.*/) d...
...|filename, count, line|
"filename = #{filename}, count = #{count}, line = #{line}"
end
end

# => "filename = sample1, count = 1, line = line1\n"
# => "filename = sample1, count = 2, line = line2\n"
# => "filename = sample1, count = 3, line = line3\n"
# => "filename = sample2, count = 1, line...

Enumerable#filter -> Enumerator (3107.0)

各要素に対してブロックを評価した値が真であった要素を全て含む配列を 返します。真になる要素がひとつもなかった場合は空の配列を返します。

...Enumerator を返します。

//emlist[例][ruby]{
(1..10).find_all # => #<Enumerator: 1..10:find_all>
(1..10).find_all { |i| i % 3 == 0 } # => [3, 6, 9]

[1,2,3,4,5].select # => #<Enumerator: [1, 2, 3, 4, 5]:select>
[1,2,3,4,5].select { |num| num.ev...
...en? } # => [2, 4]
//}

@see Enumerable#reject
@see Enumerable#grep...

Enumerable#find_all -> Enumerator (3107.0)

各要素に対してブロックを評価した値が真であった要素を全て含む配列を 返します。真になる要素がひとつもなかった場合は空の配列を返します。

...Enumerator を返します。

//emlist[例][ruby]{
(1..10).find_all # => #<Enumerator: 1..10:find_all>
(1..10).find_all { |i| i % 3 == 0 } # => [3, 6, 9]

[1,2,3,4,5].select # => #<Enumerator: [1, 2, 3, 4, 5]:select>
[1,2,3,4,5].select { |num| num.ev...
...en? } # => [2, 4]
//}

@see Enumerable#reject
@see Enumerable#grep...

Enumerable#lazy -> Enumerator::Lazy (3107.0)

自身を lazy な Enumerator に変換したものを返します。

...Enumerator に変換したものを返します。

この Enumerator は、以下のメソッドが遅延評価を行う (つまり、配列ではな
くEnumeratorを返す) ように再定義されています。

* map/collect
* flat_map/collect_concat
* select/find_all
* reject
* grep
* t...
...lazy)

以下はピタゴラス数 (a**2 + b**2 = c**2 を満たす自然数 a, b, c の組) を
列挙するプログラムです。

//emlist[例][ruby]{
def pythagorean_triples
(1..Float::INFINITY).lazy.flat_map {|z|
(1..z).flat_map {|x|
(x..z).select {|y|
x**2 + y**2 == z**2...
...数を表示する
p pythagorean_triples.take(10).force # takeはlazyなので、forceが必要です
p pythagorean_triples.first(10) # firstはeagerです
# 100より小さいピタゴラス数を表示する
p pythagorean_triples.take_while { |*, z| z < 100 }.force
//}

@see Enumerator::Lazy...

絞り込み条件を変える

<< 1 2 > >>