クラス
- Enumerator (155)
-
Enumerator
:: Chain (6) -
Enumerator
:: Lazy (11) -
Enumerator
:: Yielder (27) - IO (154)
- Object (44)
- OpenStruct (22)
- Pathname (70)
- Prime (44)
-
Prime
:: PseudoPrimeGenerator (44) - StopIteration (11)
- StringIO (94)
- Struct (78)
モジュール
- Enumerable (44)
- Kernel (18)
- ObjectSpace (44)
キーワード
- << (11)
- Enumerator (11)
- Fiber (11)
-
NEWS for Ruby 2
. 0 . 0 (11) -
NEWS for Ruby 2
. 2 . 0 (10) -
NEWS for Ruby 2
. 3 . 0 (9) -
NEWS for Ruby 2
. 4 . 0 (8) -
NEWS for Ruby 2
. 6 . 0 (6) -
NEWS for Ruby 2
. 7 . 0 (5) -
NEWS for Ruby 3
. 0 . 0 (4) -
NEWS for Ruby 3
. 1 . 0 (3) - Ruby用語集 (11)
- Yielder (11)
- ascend (22)
- bytes (14)
- descend (22)
- each (198)
-
each
_ byte (22) -
each
_ char (22) -
each
_ entry (26) -
each
_ line (88) -
each
_ object (44) -
each
_ pair (44) -
each
_ with _ index (44) -
enum
_ for (22) - feed (11)
- filter (12)
- find (22)
- lines (14)
- loop (18)
-
next
_ values (11) - optparse (11)
-
peek
_ values (11) - produce (5)
- result (11)
-
ruby 1
. 9 feature (11) - select (22)
- size (11)
-
to
_ enum (22) -
to
_ proc (5) -
with
_ index (44) -
with
_ object (22) - yield (11)
検索結果
先頭5件
-
Pathname
# find(ignore _ error: true) -> Enumerator (113.0) -
self 配下のすべてのファイルやディレクトリを 一つずつ引数 pathname に渡してブロックを実行します。
...name に渡してブロックを実行します。
require 'find'
Find.find(self.to_s) {|f| yield Pathname.new(f)}
と同じです。
ブロックを省略した場合は Enumerator を返します。
@param ignore_error 探索中に発生した例外を無視するかどうかを指定し... -
Prime
. each(upper _ bound = nil , generator = EratosthenesGenerator . new) {|prime| . . . } -> object (109.0) -
Prime.instance.each と同じです。
...。
@param generator 素数生成器のインスタンスを指定します。
@return ブロックの最後に評価された値を返します。
ブロックが与えられなかった場合は、Enumerator と互換性のある外部イテレータを返します。
@see Prime#each... -
StringIO
# each(rs = $ / ) -> Enumerator (109.0) -
自身から 1 行ずつ読み込み、それを引数として与えられたブロックを実行します。
...連続する改行を行の区切りとみなします(パラグラフモード)。
@raise IOError 自身が読み取り不可なら発生します。
//emlist[例][ruby]{
require "stringio"
a = StringIO.new("hoge\nfoo\n")
a.each{|l| p l }
#=> "hoge\n"
# "foo\n"
//}
@see $/
@see IO#each_line... -
StringIO
# each _ line(rs = $ / ) -> Enumerator (109.0) -
自身から 1 行ずつ読み込み、それを引数として与えられたブロックを実行します。
...連続する改行を行の区切りとみなします(パラグラフモード)。
@raise IOError 自身が読み取り不可なら発生します。
//emlist[例][ruby]{
require "stringio"
a = StringIO.new("hoge\nfoo\n")
a.each{|l| p l }
#=> "hoge\n"
# "foo\n"
//}
@see $/
@see IO#each_line... -
StringIO
# lines(rs = $ / ) -> Enumerator (109.0) -
自身から 1 行ずつ読み込み、それを引数として与えられたブロックを実行します。
...連続する改行を行の区切りとみなします(パラグラフモード)。
@raise IOError 自身が読み取り不可なら発生します。
//emlist[例][ruby]{
require "stringio"
a = StringIO.new("hoge\nfoo\n")
a.each{|l| p l }
#=> "hoge\n"
# "foo\n"
//}
@see $/
@see IO#each_line... -
StringIO
# bytes -> Enumerator (108.0) -
自身から 1 バイトずつ読み込み、整数 ch に変換し、それを引数として与えられたブロックを実行します。
...変換し、それを引数として与えられたブロックを実行します。
@raise IOError 自身が読み取り不可なら発生します。
//emlist[例][ruby]{
require "stringio"
a = StringIO.new("hoge")
a.each_byte{|ch| p ch }
#=> 104
# 111
# 103
# 101
//}
@see IO#each_byte... -
StringIO
# each(rs = $ / ) -> Enumerator (108.0) -
自身から 1 行ずつ読み込み、それを引数として与えられたブロックを実行します。
...連続する改行を行の区切りとみなします(パラグラフモード)。
@raise IOError 自身が読み取り不可なら発生します。
//emlist[例][ruby]{
require "stringio"
a = StringIO.new("hoge\nfoo\n")
a.each{|l| p l }
#=> "hoge\n"
# "foo\n"
//}
@see $/
@see IO#each_line... -
StringIO
# each _ byte -> Enumerator (108.0) -
自身から 1 バイトずつ読み込み、整数 ch に変換し、それを引数として与えられたブロックを実行します。
...変換し、それを引数として与えられたブロックを実行します。
@raise IOError 自身が読み取り不可なら発生します。
//emlist[例][ruby]{
require "stringio"
a = StringIO.new("hoge")
a.each_byte{|ch| p ch }
#=> 104
# 111
# 103
# 101
//}
@see IO#each_byte... -
StringIO
# each _ line(rs = $ / ) -> Enumerator (108.0) -
自身から 1 行ずつ読み込み、それを引数として与えられたブロックを実行します。
...連続する改行を行の区切りとみなします(パラグラフモード)。
@raise IOError 自身が読み取り不可なら発生します。
//emlist[例][ruby]{
require "stringio"
a = StringIO.new("hoge\nfoo\n")
a.each{|l| p l }
#=> "hoge\n"
# "foo\n"
//}
@see $/
@see IO#each_line... -
StringIO
# each _ byte -> Enumerator (107.0) -
自身から 1 バイトずつ読み込み、整数 ch に変換し、それを引数として与えられたブロックを実行します。
...変換し、それを引数として与えられたブロックを実行します。
@raise IOError 自身が読み取り不可なら発生します。
//emlist[例][ruby]{
require "stringio"
a = StringIO.new("hoge")
a.each_byte{|ch| p ch }
#=> 104
# 111
# 103
# 101
//}
@see IO#each_byte... -
optparse (102.0)
-
コマンドラインのオプションを取り扱うためのライブラリです。
...オプション -a, -b を受け付けるコマンドを作成する例です。
//emlist[sample.rb][ruby]{
require 'optparse'
opt = OptionParser.new
opt.on('-a') {|v| p v }
opt.on('-b') {|v| p v }
opt.parse!(ARGV)
p ARGV
//}
↓
ruby sample.rb -a foo bar -b baz
# => true......述します。ブロックの引数にはオプションが指定
されたことを示す true が渡されます(optionargの項も参照)。
Enumerator#each などと違い、OptionParser#on
メソッドが呼ばれた時点ではブロックは実行されません。あくまで登録され......除かれます。
これを避けるには OptionParser#parse を使います。
//emlist[sample.rb][ruby]{
require 'optparse'
opt = OptionParser.new
opt.on('-a') {|v| p v }
opt.on('-b') {|v| p v }
# parse() の場合、ARGVは変更されない。
# オプションを取り除いた結果は ar... -
Fiber (42.0)
-
ノンプリエンプティブな軽量スレッド(以下ファイバーと呼ぶ)を提供します。 他の言語では coroutine あるいは semicoroutine と呼ばれることもあります。 Thread と違いユーザレベルスレッドとして実装されています。
...= 例外
ファイバー実行中に例外が発生した場合、親ファイバーに例外が伝播します。
//emlist[例:][ruby]{
f = Fiber.new do
raise StandardError, "hoge"
end
begin
f.resume # ここでも StandardError が発生する。
rescue => e
p e.message #=> "hoge"
end
//......他のルーチンにコンテキストを切り替え、またそのポイントから再開する
という目的のために使います。
Fiber.new により与えられたブロックとともにファイバーを生成します。
生成したファイバーに対して Fiber#resume を呼ぶ......。
//emlist[例:][ruby]{
f = Fiber.new do
n = 0
loop do
Fiber.yield(n)
n += 1
end
end
5.times do
p f.resume
end
#=> 0
1
2
3
4
//}
以下は内部イテレータを外部イテレータに変換する例です。
実際 Enumerator は Fiber を用いて実装され... -
Kernel
. # loop { . . . } -> object | nil (35.0) -
(中断されない限り)永遠にブロックの評価を繰り返します。 ブロックが指定されなければ、代わりに Enumerator を返します。
...れば、代わりに Enumerator を返します。
//emlist[例][ruby]{
loop do
print "Input: "
line = gets
break if !line or line =~ /^qQ/
# ...
end
//}
与えられたブロック内で StopIteration を Kernel.#raise すると
ループを終了して Enumerator が最後に返した......値を返します。
ループを終了させる場合、通常は break を使用してください。
//emlist[例][ruby]{
enum = Enumerator.new { |y|
y << "one"
y << "two"
:ok
}
result = loop {
puts enum.next
} # => :ok
//}
@return break の引数など、ループ脱出時の値を... -
ObjectSpace
. # each _ object {|object| . . . } -> Integer (32.0) -
指定された klass と Object#kind_of? の関係にある全ての オブジェクトに対して繰り返します。引数が省略された時には全てのオブ ジェクトに対して繰り返します。 繰り返した数を返します。
...のオブ
ジェクトに対して繰り返します。
繰り返した数を返します。
ブロックが与えられなかった場合は、
Enumerator オブジェクトを返します。
次のクラスのオブジェクトについては繰り返しません
* Fixnum
* Symbol
* TrueClas......す。
@param klass クラスかモジュールを指定します。
//emlist[例: ブロックなし][ruby]{
p ObjectSpace.each_object
# => #<Enumerator: ObjectSpace:each_object(false)>
//}
//emlist[例: 全てのオブジェクトを扱う][ruby]{
ObjectSpace.each_object.take(5).each { |x| p x......ss_names"
# => "@corrections"
# => Total count: 9938
//}
//emlist[例: 任意のクラスを扱う][ruby]{
Person = Struct.new(:name)
s1 = Person.new("tanaka")
s2 = Person.new("sato")
count = ObjectSpace.each_object(Person) { |x| p x }
puts "Total count: #{count}"
# => #<struct Person name="sato"...