るりまサーチ

最速Rubyリファレンスマニュアル検索!
385件ヒット [101-200件を表示] (0.126秒)

別のキーワード

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

ライブラリ

クラス

モジュール

キーワード

検索結果

<< < 1 2 3 4 > >>

Enumerable#take_while {|element| ... } -> Array (6121.0)

Enumerable オブジェクトの要素を順に偽になるまでブロックで評価します。 最初に偽になった要素の手前の要素までを配列として返します。

...クで評価します。
最初に偽になった要素の手前の要素までを配列として返します。

//emlist[例][ruby]{
e = [1, 2, 3, 4, 5, 0].each
e.take_while {|i| i < 3 } # => [1, 2]
//}

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

@see Array#take_while...

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

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

...Enumeratorを返す) ように再定義されています。

* map/collect
* flat_map/collect_concat
* select/find_all
* reject
* grep
* take, take_while
* drop, drop_while
* zip (※一貫性のため、ブロックを渡さないケースのみlazy)
* cycle (※一貫性のため、ブ...
...t[例][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).f...
...orce # takeはlazyなので、forceが必要です
p pythagorean_triples.first(10) # firstはeagerです
# 100より小さいピタゴラス数を表示する
p pythagorean_triples.take_while { |*, z| z < 100 }.force
//}

@see Enumerator::Lazy...

Enumerator::Lazy#force(*args) -> [object] (19.0)

全ての要素を含む配列を返します。Lazy から実際に値を取り出すのに使います。

...要素を含む配列を返します。Lazy から実際に値を取り出すのに使います。

Enumerable#to_a のエイリアスです。

//emlist[例][ruby]{
1.step.lazy.take(10).force
# => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

1.step.lazy.take(10).to_a
# => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}...

Range#%(s) -> Enumerator (19.0)

範囲内の要素を s おきに繰り返します。

...す。
@return ブロックを指定しなかったその他の Range の時は Enumerator を返します。(例: String の Range)

//emlist[例][ruby]{
(1..10).step(3) {|v| p v}
# => 1
# 4
# 7
# 10

("a".."f").step(2) {|v| p v}
# => "a"
# "c"
# "e"

(10..0).step(-3) {|v| p v}
# =>...
...(文字列またはシンボルの Range で s に数値を指定した場合を除きます)

//emlist[数値以外の Range に対する例][ruby]{
# Time の Range は each でイテレートできない
(Time.utc(2024, 12, 25)...Time.utc(2024, 12, 26)).each { |t| p t }
# => 'Range#each': ca...
...rate from Time (TypeError)

# step は使用可能
(Time.utc(2024, 12, 25)...Time.utc(2024, 12, 26)).step(60*60*6) { |t| p t }
# => 2024-12-25 00:00:00 UTC
# 2024-12-25 06:00:00 UTC
# 2024-12-25 12:00:00 UTC
# 2024-12-25 18:00:00 UTC

("a"..).step("*").take(3) # => ["a", "a*", "a**"]
//}...

Range#%(s) -> Enumerator::ArithmeticSequence (19.0)

範囲内の要素を s おきに繰り返します。

...す。
@return ブロックを指定しなかったその他の Range の時は Enumerator を返します。(例: String の Range)

//emlist[例][ruby]{
(1..10).step(3) {|v| p v}
# => 1
# 4
# 7
# 10

("a".."f").step(2) {|v| p v}
# => "a"
# "c"
# "e"

(10..0).step(-3) {|v| p v}
# =>...
...(文字列またはシンボルの Range で s に数値を指定した場合を除きます)

//emlist[数値以外の Range に対する例][ruby]{
# Time の Range は each でイテレートできない
(Time.utc(2024, 12, 25)...Time.utc(2024, 12, 26)).each { |t| p t }
# => 'Range#each': ca...
...rate from Time (TypeError)

# step は使用可能
(Time.utc(2024, 12, 25)...Time.utc(2024, 12, 26)).step(60*60*6) { |t| p t }
# => 2024-12-25 00:00:00 UTC
# 2024-12-25 06:00:00 UTC
# 2024-12-25 12:00:00 UTC
# 2024-12-25 18:00:00 UTC

("a"..).step("*").take(3) # => ["a", "a*", "a**"]
//}...

絞り込み条件を変える

Range#step(s = 1) -> Enumerator (19.0)

範囲内の要素を s おきに繰り返します。

...す。
@return ブロックを指定しなかったその他の Range の時は Enumerator を返します。(例: String の Range)

//emlist[例][ruby]{
(1..10).step(3) {|v| p v}
# => 1
# 4
# 7
# 10

("a".."f").step(2) {|v| p v}
# => "a"
# "c"
# "e"

(10..0).step(-3) {|v| p v}
# =>...
...(文字列またはシンボルの Range で s に数値を指定した場合を除きます)

//emlist[数値以外の Range に対する例][ruby]{
# Time の Range は each でイテレートできない
(Time.utc(2024, 12, 25)...Time.utc(2024, 12, 26)).each { |t| p t }
# => 'Range#each': ca...
...rate from Time (TypeError)

# step は使用可能
(Time.utc(2024, 12, 25)...Time.utc(2024, 12, 26)).step(60*60*6) { |t| p t }
# => 2024-12-25 00:00:00 UTC
# 2024-12-25 06:00:00 UTC
# 2024-12-25 12:00:00 UTC
# 2024-12-25 18:00:00 UTC

("a"..).step("*").take(3) # => ["a", "a*", "a**"]
//}...

Range#step(s = 1) -> Enumerator::ArithmeticSequence (19.0)

範囲内の要素を s おきに繰り返します。

...す。
@return ブロックを指定しなかったその他の Range の時は Enumerator を返します。(例: String の Range)

//emlist[例][ruby]{
(1..10).step(3) {|v| p v}
# => 1
# 4
# 7
# 10

("a".."f").step(2) {|v| p v}
# => "a"
# "c"
# "e"

(10..0).step(-3) {|v| p v}
# =>...
...(文字列またはシンボルの Range で s に数値を指定した場合を除きます)

//emlist[数値以外の Range に対する例][ruby]{
# Time の Range は each でイテレートできない
(Time.utc(2024, 12, 25)...Time.utc(2024, 12, 26)).each { |t| p t }
# => 'Range#each': ca...
...rate from Time (TypeError)

# step は使用可能
(Time.utc(2024, 12, 25)...Time.utc(2024, 12, 26)).step(60*60*6) { |t| p t }
# => 2024-12-25 00:00:00 UTC
# 2024-12-25 06:00:00 UTC
# 2024-12-25 12:00:00 UTC
# 2024-12-25 18:00:00 UTC

("a"..).step("*").take(3) # => ["a", "a*", "a**"]
//}...

Range#step(s = 1) {|item| ... } -> self (19.0)

範囲内の要素を s おきに繰り返します。

...す。
@return ブロックを指定しなかったその他の Range の時は Enumerator を返します。(例: String の Range)

//emlist[例][ruby]{
(1..10).step(3) {|v| p v}
# => 1
# 4
# 7
# 10

("a".."f").step(2) {|v| p v}
# => "a"
# "c"
# "e"

(10..0).step(-3) {|v| p v}
# =>...
...(文字列またはシンボルの Range で s に数値を指定した場合を除きます)

//emlist[数値以外の Range に対する例][ruby]{
# Time の Range は each でイテレートできない
(Time.utc(2024, 12, 25)...Time.utc(2024, 12, 26)).each { |t| p t }
# => 'Range#each': ca...
...rate from Time (TypeError)

# step は使用可能
(Time.utc(2024, 12, 25)...Time.utc(2024, 12, 26)).step(60*60*6) { |t| p t }
# => 2024-12-25 00:00:00 UTC
# 2024-12-25 06:00:00 UTC
# 2024-12-25 12:00:00 UTC
# 2024-12-25 18:00:00 UTC

("a"..).step("*").take(3) # => ["a", "a*", "a**"]
//}...

Enumerator::Lazy#chunk {|elt| ... } -> Enumerator::Lazy (13.0)

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

...ではなく Enumerator::Lazy を返します。

//emlist[例][ruby]{
1.step.lazy.chunk{ |n| n % 3 == 0 }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x007f8bf18118f0>:each>>

1.step.lazy.chunk{ |n| n % 3 == 0 }.take(5).force
# => [[false, [1, 2]], [true, [3]], [false, [4, 5]], [...

Enumerator::Lazy#chunk(initial_state) {|elt, state| ... } -> Enumerator::Lazy (13.0)

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

...ではなく Enumerator::Lazy を返します。

//emlist[例][ruby]{
1.step.lazy.chunk{ |n| n % 3 == 0 }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x007f8bf18118f0>:each>>

1.step.lazy.chunk{ |n| n % 3 == 0 }.take(5).force
# => [[false, [1, 2]], [true, [3]], [false, [4, 5]], [...

絞り込み条件を変える

Enumerator::Lazy#collect {|item| ... } -> Enumerator::Lazy (13.0)

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

...ックを指定しなかった場合に発生します。

//emlist[例][ruby]{
1.step.lazy.map{ |n| n % 3 == 0 }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:map>

1.step.lazy.collect{ |n| n.succ }.take(10).force
# => [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
//}

@see Enumerable#map...

Enumerator::Lazy#drop(n) -> Enumerator::Lazy (13.0)

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

...@raise ArgumentError n に負の数を指定した場合に発生します。

//emlist[例][ruby]{
1.step.lazy.drop(3)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:drop(3)>

1.step.lazy.drop(3).take(10).force
# => [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
//}

@see Enumerable#drop...

Enumerator::Lazy#drop_while {|item| ... } -> Enumerator::Lazy (13.0)

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

...列ではなくEnumerator::Lazy を返します。

//emlist[例][ruby]{
1.step.lazy.drop_while { |i| i < 42 }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:drop_while>

1.step.lazy.drop_while { |i| i < 42 }.take(10).force
# => [42, 43, 44, 45, 46, 47, 48, 49, 50, 51]
//}

@see...

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

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

...を指定しなかった場合に発生します。

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

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

@see Enumerab...
<< < 1 2 3 4 > >>