るりまサーチ

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

別のキーワード

  1. _builtin take_while
  2. _builtin take
  3. array take_while
  4. lazy take_while
  5. enumerable take_while

ライブラリ

クラス

モジュール

キーワード

検索結果

Enumerator::Lazy#take_while {|item| ... } -> Enumerator::Lazy (24509.0)

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

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

//emlist[例][ruby]{
1.step.lazy.zip(('a'..'z').cycle).take_while { |e| e.first < 100_000 }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:zip(#<Enumerator: "a"...
....."z":cycle>)>:take_while>

1.step.lazy.zip(('a'..'z').cycle).take_while { |e| e.first < 100_000 }.force.last(5)
# => [[99995, "y"], [99996, "z"], [99997, "a"], [99998, "b"], [99999, "c"]]
//}

@see Enumerable#take_while...

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

配列の要素を順に偽になるまでブロックで評価します。 最初に偽になった要素の手前の要素までを配列として返します。 このメソッドは自身を破壊的に変更しません。

...の要素までを配列として返します。
このメソッドは自身を破壊的に変更しません。

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

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

@see Enumerable#take_while...

Enumerable#take_while {|element| ... } -> Array (24435.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...

Enumerator::Lazy#take_while -> Enumerator::Lazy (24409.0)

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

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

//emlist[例][ruby]{
1.step.lazy.zip(('a'..'z').cycle).take_while { |e| e.first < 100_000 }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:zip(#<Enumerator: "a"...
....."z":cycle>)>:take_while>

1.step.lazy.zip(('a'..'z').cycle).take_while { |e| e.first < 100_000 }.force.last(5)
# => [[99995, "y"], [99996, "z"], [99997, "a"], [99998, "b"], [99999, "c"]]
//}

@see Enumerable#take_while...

Array#take_while -> Enumerator (24335.0)

配列の要素を順に偽になるまでブロックで評価します。 最初に偽になった要素の手前の要素までを配列として返します。 このメソッドは自身を破壊的に変更しません。

...の要素までを配列として返します。
このメソッドは自身を破壊的に変更しません。

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

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

@see Enumerable#take_while...

絞り込み条件を変える

Enumerable#take_while -> Enumerator (24335.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...

NEWS for Ruby 3.0.0 (330.0)

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

...osplatting. This now matches the behavior of Procs
accepting a single rest argument and no keywords.
16166

//emlist[][ruby]{
pr = proc{|*a, **kw| [a, kw]}

pr.call([1])
# 2.7 => [[1], {}]
# 3.0 => [[[1]], {}]

pr.call([1, {a: 1}])
# 2.7 => [[1], {:a=>1}] # and deprecation warning
# 3.0 =>...
...mlist{
def method_missing(meth, ...)
send(:"do_#{meth}", ...)
end
//}

* Pattern matching (`case/in`) is no longer experimental. 17260
* One-line pattern matching is redesigned. [EXPERIMENTAL]
* `=>` is added. It can be used like a rightward assignment.
17260
* `in...
...ning. yield in a class definition outside of a method
is now a SyntaxError instead of a LocalJumpError. 15575
* When a class variable is overtaken by the same definition in an
ancestor class/module, a RuntimeError is now raised (previously,
it only issued a warning in verbose mode)....

Enumerator.produce(initial = nil) { |prev| ... } -> Enumerator (238.0)

与えられたブロックを呼び出し続ける、停止しない Enumerator を返します。 ブロックの戻り値が、次にブロックを呼び出す時に引数として渡されます。 initial 引数が渡された場合、最初にブロックを呼び出す時にそれがブロック 呼び出しの引数として渡されます。initial が渡されなかった場合は nil が 渡されます。

...}

# ツリー構造の祖先ノードを列挙する Enumerator
ancestors = Enumerator.produce(node) { |prev| node = prev.parent or raise StopIteration }
enclosing_section = ancestors.find { |n| n.type == :section }
//}

このメソッドは Enumerable の各メソッドと組み合わせて使...
...ことで、
while や until ループのような処理を実装できます。
例えば Enumerable#detect, Enumerable#slice_after, Enumerable#take_while
などと合わせて使えるでしょう。

//emlist[Enumerable のメソッドと組み合わせる例][ruby]{
# 次の火曜日を返す例...
..."date"
Enumerator.produce(Date.today, &:succ).detect(&:tuesday?)

# シンプルなレキサーの例
require "strscan"
scanner = StringScanner.new("7+38/6")
PATTERN = %r{\d+|[-/+*]}
Enumerator.produce { scanner.scan(PATTERN) }.slice_after { scanner.eos? }.first
# => ["7", "+", "38", "/", "6"]
//}...

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

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

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

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

@see Enumerator::Lazy...