るりまサーチ

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

別のキーワード

  1. fiddle ruby_free
  2. rbconfig ruby
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

Enumerator::Lazy#select {|item| ... } -> Enumerator::Lazy (21342.0)

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

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

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

//emlist[例][ruby]{
1.step.lazy.find_all { |i| i.even? }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:ste...
...p>>:find_all>

1.step.lazy.select { |i| i.even? }.take(10).force
# => [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
//}

@see Enumerable#select...

Array#select -> Enumerator (21245.0)

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

...の配列を返します。

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

//emlist[例][ruby]{
[1,2,3,4,5].select # => #<Enumerator: [1, 2, 3, 4, 5]:select>
[1,2,3,4,5].select { |num| num.even? } # => [2, 4]
//}
@see Enumerable#select
@see Array#select!...

Array#values_at(*selectors) -> Array (9362.0)

引数で指定されたインデックスに対応する要素を配列で返します。インデッ クスに対応する値がなければ nil が要素になります。

...す。

@param selectors インデックスを整数もしくは整数の Range で指定します。

//emlist[例][ruby]{
ary = %w( a b c d e )
p ary.values_at( 0, 2, 4 ) #=> ["a", "c", "e"]
p ary.values_at( 3, 4, 5, 6, 35 ) #=> ["d", "e", nil, nil, nil]
p ary.values_at( 0, -1, -2 )...
...=> ["a", "e", "d"]
p ary.values_at( -4, -5, -6, -35 ) #=> ["b", "a", nil, nil]
p ary.values_at( 1..2 ) #=> ["b", "c"]
p ary.values_at( 3..10 ) #=> ["d", "e", nil, nil, nil, nil, nil, nil]
p ary.values_at( 6..7 ) #=> [nil, nil]
p ary.values_at( 0, 3..5 ) #...

Array#select! -> Enumerator (9227.0)

ブロックが真を返した要素を残し、偽を返した要素を自身から削除します。 変更があった場合は self を、 変更がなかった場合には nil を返します。

...//emlist[例][ruby]{
a = %w{ a b c d e f }
a.select! {|v| v =~ /[a-z]/ } # => nil
a # => ["a", "b", "c", "d", "e", "f"]
//}

ブロックが与えられなかった場合は、自身と select! から生成した
Enumerator オブジェクトを返します。

@see Array#keep_if, Array#reject!...

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

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

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

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

* map/collect
* flat_map/collect_concat
* select/find_all
*...
...lazy)
* cycle (※一貫性のため、ブロックを渡さないケースのみ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
}.map {|y|
[x, y, z]
}
}
}
end
# 最初の10個のピタゴラス数を表示する
p pythagorean_triples.take(10).force # takeはlazyなので、forceが必要です
p pythagorean_triples.fir...

絞り込み条件を変える

Enumerator::Lazy#filter {|item| ... } -> Enumerator::Lazy (6242.0)

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

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

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

//emlist[例][ruby]{
1.step.lazy.find_all { |i| i.even? }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:ste...
...p>>:find_all>

1.step.lazy.select { |i| i.even? }.take(10).force
# => [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
//}

@see Enumerable#select...

Enumerator::Lazy#find_all {|item| ... } -> Enumerator::Lazy (6242.0)

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

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

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

//emlist[例][ruby]{
1.step.lazy.find_all { |i| i.even? }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:ste...
...p>>:find_all>

1.step.lazy.select { |i| i.even? }.take(10).force
# => [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
//}

@see Enumerable#select...

Array#select! -> Enumerator (6227.0)

ブロックが真を返した要素を残し、偽を返した要素を自身から削除します。 変更があった場合は self を、 変更がなかった場合には nil を返します。

...//emlist[例][ruby]{
a = %w{ a b c d e f }
a.select! {|v| v =~ /[a-z]/ } # => nil
a # => ["a", "b", "c", "d", "e", "f"]
//}

ブロックが与えられなかった場合は、自身と select! から生成した
Enumerator オブジェクトを返します。

@see Array#keep_if, Array#reject!...

Enumerator::Lazy#eager -> Enumerator (6137.0)

自身を遅延評価しない Enumerator に変換して返します。

...評価しない Enumerator に変換して返します。

//emlist[例][ruby]{
lazy_enum = (1..).each.lazy

# select が遅延評価されるので終了する
p lazy_enum.class # => Enumerator::Lazy
p lazy_enum.select { |n| n.even? }.first(5)
# => [2, 4, 6, 8, 10]

# select が遅延評価され...
...ないので終了しない
enum = lazy_enum.eager
p enum.class # => Enumerator
p enum.select { |n| n.even? }.first(5)
//}...

Array#filter -> Enumerator (3145.0)

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

...の配列を返します。

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

//emlist[例][ruby]{
[1,2,3,4,5].select # => #<Enumerator: [1, 2, 3, 4, 5]:select>
[1,2,3,4,5].select { |num| num.even? } # => [2, 4]
//}
@see Enumerable#select
@see Array#select!...

絞り込み条件を変える

Array#keep_if -> Enumerator (3137.0)

ブロックが真を返した要素を残し、偽を返した要素を自身から削除します。

...[例][ruby]{
a = %w{ a b c d e f }
a.keep_if {|v| v =~ /[aeiou]/} # => ["a", "e"]
a # => ["a", "e"]
//}

keep_if は常に self を返しますが、Array#select! は要素が 1 つ以上削除されれば self を、
1 つも削除されなければ nil を返します。

//emlist[例][ruby]{
a...
...a b c d e f }
a.keep_if {|v| v =~ /[a-z]/ } # => ["a", "b", "c", "d", "e", "f"]
a # => ["a", "b", "c", "d", "e", "f"]
//}

ブロックが与えられなかった場合は、自身と keep_if から生成した
Enumerator オブジェクトを返します。

@see Array#select!, Array#delete_if...
<< 1 2 > >>