ライブラリ
クラス
-
ARGF
. class (252) - Addrinfo (24)
- Array (660)
- CSV (24)
- Dir (118)
- Enumerator (176)
-
Enumerator
:: ArithmeticSequence (98) -
Enumerator
:: Chain (42) -
Enumerator
:: Lazy (298) -
Enumerator
:: Yielder (30) -
Etc
:: Group (24) -
Etc
:: Passwd (24) -
Gem
:: SourceIndex (24) - Hash (344)
- IO (324)
- Integer (24)
- Matrix (236)
- Numeric (93)
- Object (78)
- OpenStruct (24)
- Pathname (126)
- Prime (48)
-
Prime
:: PseudoPrimeGenerator (72) -
Psych
:: Nodes :: Node (24) -
REXML
:: Parent (96) - Range (97)
- StopIteration (12)
- String (208)
- StringIO (169)
- Struct (86)
- Vector (160)
-
Zlib
:: GzipReader (72)
モジュール
- Enumerable (789)
- Find (24)
- Kernel (48)
- ObjectSpace (48)
- TSort (132)
オブジェクト
- ENV (230)
-
Readline
:: HISTORY (24)
キーワード
- % (14)
- + (7)
- << (12)
- == (7)
- ArithmeticSequence (7)
- Chain (7)
- Enumerable (12)
- Fiber (12)
-
NEWS for Ruby 2
. 0 . 0 (12) -
NEWS for Ruby 2
. 2 . 0 (11) -
NEWS for Ruby 2
. 3 . 0 (10) -
NEWS for Ruby 2
. 4 . 0 (9) -
NEWS for Ruby 2
. 6 . 0 (7) -
NEWS for Ruby 2
. 7 . 0 (6) -
NEWS for Ruby 3
. 0 . 0 (5) -
NEWS for Ruby 3
. 1 . 0 (4) - Ruby用語集 (12)
- ascend (24)
- begin (7)
- bsearch (48)
-
bsearch
_ index (20) - build (24)
- bytes (35)
- chain (7)
- chars (42)
- chunk (36)
-
chunk
_ while (21) - codepoints (42)
- collect (108)
- collect! (52)
- collect2 (24)
-
collect
_ concat (36) - combination (24)
- combine (16)
- compact (4)
- cycle (48)
-
delete
_ if (72) - descend (24)
- detect (24)
-
drop
_ while (48) - each (628)
- each2 (24)
-
each
_ byte (120) -
each
_ char (96) -
each
_ child (94) -
each
_ codepoint (96) -
each
_ cons (24) -
each
_ entry (30) -
each
_ grapheme _ cluster (16) -
each
_ index (48) -
each
_ key (48) -
each
_ line (216) -
each
_ object (48) -
each
_ pair (96) -
each
_ prime (24) -
each
_ slice (24) -
each
_ strongly _ connected _ component (44) -
each
_ strongly _ connected _ component _ from (44) -
each
_ value (48) -
each
_ with _ index (72) -
each
_ with _ object (24) - end (7)
-
enum
_ for (48) -
exclude
_ end? (7) - filter (56)
- filter! (42)
-
filter
_ map (12) - find (72)
-
find
_ all (24) -
find
_ index (108) - first (14)
-
flat
_ map (36) - force (12)
- foreach (120)
-
group
_ by (24) - gsub (72)
- gsub! (48)
- hash (7)
- index (72)
- inspect (14)
-
keep
_ if (72) - last (14)
- lazy (12)
- lines (98)
- loop (24)
- map (108)
- map! (52)
- map2 (12)
-
max
_ by (48) -
min
_ by (48) -
minmax
_ by (24) - new (26)
- next (12)
-
next
_ values (12) - optparse (12)
- partition (24)
- peek (12)
-
peek
_ values (12) - permutation (24)
- prime (12)
- produce (6)
- reject (108)
- reject! (72)
-
repeated
_ combination (24) - result (12)
-
reverse
_ each (52) - rewind (7)
- rindex (36)
-
ruby 1
. 9 feature (12) - select (132)
- select! (72)
- size (26)
-
slice
_ after (46) -
slice
_ before (60) -
slice
_ when (23) -
sort
_ by (24) -
sort
_ by! (24) - step (131)
-
take
_ while (72) - then (14)
-
to
_ enum (48) -
to
_ proc (6) -
transform
_ keys (20) -
transform
_ keys! (20) -
transform
_ values (18) -
transform
_ values! (18) -
tsort
_ each (44) -
with
_ index (48) -
with
_ object (48) - yield (12)
-
yield
_ self (16) - zip (24)
検索結果
先頭5件
-
Enumerator (38052.0)
-
each 以外のメソッドにも Enumerable の機能を提供するためのラッパークラスです。 また、外部イテレータとしても使えます。
...each 以外のメソッドにも Enumerable の機能を提供するためのラッパークラスです。
また、外部イテレータとしても使えます。
Enumerable モジュールは、 Module#include 先のクラスが持つ
each メソッドを元に様々なメソッドを提供し......Array#each の繰り返しを元にして定義されます。
Enumerator を介することにより String#each_byte のような
異なる名前のイテレータについても each と同様に Enumerable の機能を利用できます。
Enumerator を生成するには Enumerator.newある......いは
Object#to_enum, Object#enum_for を利用します。また、一部の
イテレータはブロックを渡さずに呼び出すと繰り返しを実行する代わりに
enumerator を生成して返します。
=== 注意
外部イテレータとしての機能は Fiber を用いて実装... -
Enumerator
. produce(initial = nil) { |prev| . . . } -> Enumerator (27271.0) -
与えられたブロックを呼び出し続ける、停止しない Enumerator を返します。 ブロックの戻り値が、次にブロックを呼び出す時に引数として渡されます。 initial 引数が渡された場合、最初にブロックを呼び出す時にそれがブロック 呼び出しの引数として渡されます。initial が渡されなかった場合は nil が 渡されます。
...与えられたブロックを呼び出し続ける、停止しない Enumerator を返します。
ブロックの戻り値が、次にブロックを呼び出す時に引数として渡されます。
initial 引数が渡された場合、最初にブロックを呼び出す時にそれがブロ......く Enumerator
Enumerator.produce(1, &:succ)
# next を呼ぶたびランダムな数値を返す Enumerator
Enumerator.produce { rand(10) }
# ツリー構造の祖先ノードを列挙する Enumerator
ancestors = Enumerator.produce(node) { |prev| node = prev.parent or raise StopIteration }
enclo......sing_section = ancestors.find { |n| n.type == :section }
//}
このメソッドは Enumerable の各メソッドと組み合わせて使うことで、
while や until ループのような処理を実装できます。
例えば Enumerable#detect, Enumerable#slice_after, Enumerable#take_while
な... -
Enumerator
# with _ object(obj) -> Enumerator (27225.0) -
繰り返しの各要素に obj を添えてブロックを繰り返し、obj を返り値として返します。
...、
最後に obj を返す Enumerator を返します。
//emlist[例][ruby]{
# 0,1,2 と呼びだす enumeratorを作る
to_three = Enumerator.new do |y|
3.times do |x|
y << x
end
end
to_three_with_string = to_three.with_object("foo")
to_three_with_string.each do |x,string|
puts "#{str......ing}: #{x}"
end
# => foo:0
# => foo:1
# => foo:2
//}
@param obj 繰り返しの各要素に添えて渡されるオブジェクト
@see Enumerable#each_with_object... -
Enumerator
# with _ object(obj) {|(*args) , memo _ obj| . . . } -> object (27225.0) -
繰り返しの各要素に obj を添えてブロックを繰り返し、obj を返り値として返します。
...、
最後に obj を返す Enumerator を返します。
//emlist[例][ruby]{
# 0,1,2 と呼びだす enumeratorを作る
to_three = Enumerator.new do |y|
3.times do |x|
y << x
end
end
to_three_with_string = to_three.with_object("foo")
to_three_with_string.each do |x,string|
puts "#{str......ing}: #{x}"
end
# => foo:0
# => foo:1
# => foo:2
//}
@param obj 繰り返しの各要素に添えて渡されるオブジェクト
@see Enumerable#each_with_object... -
Enumerator
# each(*args) -> Enumerator (27207.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。
...Ruby Hacker"
enum = Enumerator.new {|y| str.scan(/\w+/) {|w| y << w }}
enum.each {|word| p word } # => "Yet"
# "Another"
# "Ruby"
# "Hacker"
str.scan(/\w+/......# "Hacker"
//}
//emlist[例2][ruby]{
"Hello, world!".scan(/\w+/) # => ["Hello", "world"]
"Hello, world!".to_enum(:scan, /\w+/).to_a # => ["Hello", "world"]
"Hello, world!".to_enum(:scan).each(/\w+/).to_a # => ["Hello", "world"]
obj = Object.new
def obj.each_arg(a, b......obj.to_enum :each_arg, :a, :x
enum.each.to_a # => [:a, :x, []]
enum.each.equal?(enum) # => true
enum.each { |elm| elm } # => :method_returned
enum.each(:y, :z).to_a # => [:a, :x, [:y, :z]]
enum.each(:y, :z).equal?(enum) # => false
enum.each(:y, :z) { |el... -
Enumerator
# each -> self (27107.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。
...Ruby Hacker"
enum = Enumerator.new {|y| str.scan(/\w+/) {|w| y << w }}
enum.each {|word| p word } # => "Yet"
# "Another"
# "Ruby"
# "Hacker"
str.scan(/\w+/......# "Hacker"
//}
//emlist[例2][ruby]{
"Hello, world!".scan(/\w+/) # => ["Hello", "world"]
"Hello, world!".to_enum(:scan, /\w+/).to_a # => ["Hello", "world"]
"Hello, world!".to_enum(:scan).each(/\w+/).to_a # => ["Hello", "world"]
obj = Object.new
def obj.each_arg(a, b......obj.to_enum :each_arg, :a, :x
enum.each.to_a # => [:a, :x, []]
enum.each.equal?(enum) # => true
enum.each { |elm| elm } # => :method_returned
enum.each(:y, :z).to_a # => [:a, :x, [:y, :z]]
enum.each(:y, :z).equal?(enum) # => false
enum.each(:y, :z) { |el... -
Enumerator
# each { . . . } -> object (27107.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。
...Ruby Hacker"
enum = Enumerator.new {|y| str.scan(/\w+/) {|w| y << w }}
enum.each {|word| p word } # => "Yet"
# "Another"
# "Ruby"
# "Hacker"
str.scan(/\w+/......# "Hacker"
//}
//emlist[例2][ruby]{
"Hello, world!".scan(/\w+/) # => ["Hello", "world"]
"Hello, world!".to_enum(:scan, /\w+/).to_a # => ["Hello", "world"]
"Hello, world!".to_enum(:scan).each(/\w+/).to_a # => ["Hello", "world"]
obj = Object.new
def obj.each_arg(a, b......obj.to_enum :each_arg, :a, :x
enum.each.to_a # => [:a, :x, []]
enum.each.equal?(enum) # => true
enum.each { |elm| elm } # => :method_returned
enum.each(:y, :z).to_a # => [:a, :x, [:y, :z]]
enum.each(:y, :z).equal?(enum) # => false
enum.each(:y, :z) { |el... -
Enumerator
# each(*args) { . . . } -> object (27107.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。
...Ruby Hacker"
enum = Enumerator.new {|y| str.scan(/\w+/) {|w| y << w }}
enum.each {|word| p word } # => "Yet"
# "Another"
# "Ruby"
# "Hacker"
str.scan(/\w+/......# "Hacker"
//}
//emlist[例2][ruby]{
"Hello, world!".scan(/\w+/) # => ["Hello", "world"]
"Hello, world!".to_enum(:scan, /\w+/).to_a # => ["Hello", "world"]
"Hello, world!".to_enum(:scan).each(/\w+/).to_a # => ["Hello", "world"]
obj = Object.new
def obj.each_arg(a, b......obj.to_enum :each_arg, :a, :x
enum.each.to_a # => [:a, :x, []]
enum.each.equal?(enum) # => true
enum.each { |elm| elm } # => :method_returned
enum.each(:y, :z).to_a # => [:a, :x, [:y, :z]]
enum.each(:y, :z).equal?(enum) # => false
enum.each(:y, :z) { |el... -
CSV
. foreach(path , options = Hash . new) -> Enumerator (26217.0) -
このメソッドは CSV ファイルを読むための主要なインターフェイスです。 各行が与えられたブロックに渡されます。 ブロックが与えられていない場合、Enumeratorを返します。
...メソッドは CSV ファイルを読むための主要なインターフェイスです。
各行が与えられたブロックに渡されます。
ブロックが与えられていない場合、Enumeratorを返します。
//emlist[例][ruby]{
require 'csv'
# UTF-32BE な CSV ファイルを......をブロックに渡します
CSV.foreach("a.csv", encoding: "UTF-32BE:UTF-8"){|row| p row }
//}
@param path CSV ファイルのパスを指定します。
@param options CSV.new のオプションと同じオプションを指定できます。
:encoding というキーを使用......入出力のエンコーディングを指定することができます。
Encoding.default_external と異なるエンコーディングを持つ入力を使用する場合は、
必ずエンコーディングを指定してください。
@see CSV.new, File.open...