58件ヒット
[1-58件を表示]
(0.044秒)
種類
- インスタンスメソッド (44)
- 特異メソッド (14)
ライブラリ
- ビルトイン (58)
キーワード
- new (14)
- next (11)
- rewind (11)
-
with
_ index (22)
検索結果
先頭5件
-
Enumerator
. new(obj , method = :each , *args) -> Enumerator (9251.0) -
オブジェクト obj について、 each の代わりに method という 名前のメソッドを使って繰り返すオブジェクトを生成して返します。 args を指定すると、 method の呼び出し時に渡されます。
...オブジェクト obj について、 each の代わりに method という
名前のメソッドを使って繰り返すオブジェクトを生成して返します。
args を指定すると、 method の呼び出し時に渡されます。
@param obj イテレータメソッドのレシーバ......method イテレータメソッドの名前を表すシンボルまたは文字列
@param args イテレータメソッドの呼び出しに渡す任意個の引数
//emlist[例][ruby]{
str = "xyz"
enum = Enumerator.new(str, :each_byte)
p enum.map {|b| '%02x' % b } # => ["78", "79", "7a"]
//}... -
Enumerator
. new(size=nil) {|y| . . . } -> Enumerator (9206.0) -
Enumerator オブジェクトを生成して返します。与えられたブロックは Enumerator::Yielder オブジェクトを 引数として実行されます。
...
Enumerator オブジェクトを生成して返します。与えられたブロックは Enumerator::Yielder オブジェクトを
引数として実行されます。
生成された Enumerator オブジェクトに対して each を呼ぶと、この生成時に指定されたブロックを......たびに、
each に渡されたブロックが繰り返されます。
new に渡されたブロックが終了した時点で each の繰り返しが終わります。
このときのブロックの返り値が each の返り値となります。
@param size 生成する Enumerator オブジェ......nil のいずれかを指定します。Enumerator#size の実
行時に参照されます。
//emlist[例][ruby]{
enum = Enumerator.new{|y|
(1..10).each{|i|
y << i if i % 5 == 0
}
}
enum.each{|i| p i }
#=> 5
# 10
fib = Enumerator.new { |y|
a = b = 1
loop {
y << a... -
Enumerator
# with _ index(offset = 0) -> Enumerator (9138.0) -
生成時のパラメータに従って、要素にインデックスを添えて繰り返します。 インデックスは offset から始まります。
...す。
//emlist[例][ruby]{
str = "xyz"
enum = Enumerator.new {|y| str.each_byte {|b| y << b }}
enum.with_index {|byte, idx| p [byte, idx] }
# => [120, 0]
# [121, 1]
# [122, 2]
require "stringio"
StringIO.new("foo|bar|baz").each("|").with_index(1) {|s, i| p [s, i] }
# => ["f......にインデックスを添えてブロックを繰り返します。
インデックスは 0 から始まります。
Enumerator#with_index は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにそのまま渡されます)。... -
Enumerator
# next -> object (9049.0) -
「次」のオブジェクトを返します。
...、 IO#each_line のようにおおもとの列挙メカニズムが副作用を
伴っている場合には影響があり得ます。
@raise StopIteration 列挙状態が既に最後へ到達しているとき
@see Enumerator#rewind
//emlist[例1][ruby]{
str = "xyz"
enum = str.each_byte
str.byt......121
# 122
//}
//emlist[例2][ruby]{
str = "xyz"
enum = str.each_byte
begin
puts enum.next while true
rescue StopIteration
puts "iteration reached at end"
end
# => 120
# 121
# 122
# iteration reached at end
puts enum.next
#=> 再度 StopIteration 例外が発......生
//}
//emlist[例3: Kernel.#loop は StopIteration を捕捉します。][ruby]{
str = "xyz"
enum = str.each_byte
loop do
puts enum.next
end
# => 120
# 121
# 122
//}... -
Enumerator
# with _ index(offset = 0) {|(*args) , idx| . . . } -> object (9038.0) -
生成時のパラメータに従って、要素にインデックスを添えて繰り返します。 インデックスは offset から始まります。
...す。
//emlist[例][ruby]{
str = "xyz"
enum = Enumerator.new {|y| str.each_byte {|b| y << b }}
enum.with_index {|byte, idx| p [byte, idx] }
# => [120, 0]
# [121, 1]
# [122, 2]
require "stringio"
StringIO.new("foo|bar|baz").each("|").with_index(1) {|s, i| p [s, i] }
# => ["f......にインデックスを添えてブロックを繰り返します。
インデックスは 0 から始まります。
Enumerator#with_index は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにそのまま渡されます)。... -
Enumerator
# rewind -> self (9019.0) -
列挙状態を巻き戻します。
...が rewind メソッドを持つとき(respond_to?(:rewind) に
真を返すとき) は、その rewind メソッドを呼び出します。
@see Enumerator#next
//emlist[例][ruby]{
str = "xyz"
enum = str.each_byte
p enum.next # => 120
p enum.next # => 121
enum.rewind
p enum.next # => 120
//}...