クラス
- Enumerator (77)
-
Enumerator
:: Lazy (55) -
Enumerator
:: Yielder (27) - Exception (22)
- Fiber (59)
-
Net
:: POP3 (11) - Object (68)
- Pathname (34)
- Proc (58)
- StopIteration (11)
- Thread (22)
モジュール
- Enumerable (91)
- Kernel (35)
キーワード
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (11) - << (11)
- == (11)
- === (11)
-
NEWS for Ruby 2
. 3 . 0 (9) -
NEWS for Ruby 2
. 5 . 0 (7) -
NEWS for Ruby 2
. 6 . 0 (6) -
NEWS for Ruby 2
. 7 . 0 (5) -
NEWS for Ruby 3
. 0 . 0 (4) - Proc (11)
- [] (22)
- alive? (11)
-
backtrace
_ locations (11) - call (11)
- compact (3)
- each (44)
-
each
_ entry (35) -
enum
_ for (44) - feed (11)
- find (21)
- foreach (11)
- lambda (17)
-
max
_ by (44) - monitor (11)
- new (25)
-
next
_ values (11) -
peek
_ values (11) - proc (18)
- raise (15)
- rdoc (11)
- result (11)
- resume (11)
-
ruby 1
. 6 feature (11) -
ruby 1
. 9 feature (11) -
sort
_ by (22) - then (6)
-
thread
_ variable _ get (11) -
to
_ enum (44) -
to
_ proc (16) - transfer (11)
-
yield
_ self (7) - クラス/メソッドの定義 (11)
- セキュリティモデル (11)
- メソッド呼び出し(super・ブロック付き・yield) (11)
- 制御構造 (11)
- 手続きオブジェクトの挙動の詳細 (11)
検索結果
先頭5件
-
Enumerator
:: Yielder # yield(*object) -> () (24219.0) -
Enumerator.new で使うメソッドです。
...Enumerator.new で使うメソッドです。
生成された Enumerator オブジェクトの each メソッドを呼ぶと
Enumerator::Yielder オブジェクトが渡されたブロックが実行され、
ブロック内の yield メソッドが呼ばれるたびに each に渡された
ブロ......ックが yield メソッドに渡された値とともに繰り返されます。
//emlist[例][ruby]{
enum = Enumerator.new do |y|
y.yield 1, 2, 3
end
enum.each do |x, y, z|
p [x, y, z]
end
# => [1, 2, 3]
//}... -
Fiber
. yield(*arg = nil) -> object (21313.0) -
現在のファイバーの親にコンテキストを切り替えます。
...Fiber#resume に与えられた引数を yield メソッドは返します。
@param arg 現在のファイバーの親に渡したいオブジェクトを指定します。
@raise FiberError Fiber でのルートファイバーで呼ばれた場合に発生します。
//emlist[例:][ruby]{
a......= nil
f = Fiber.new do
a = Fiber.yield()
end
f.resume()
f.resume(:foo)
p a #=> :foo
//}... -
Proc
# yield(*arg) -> () (18325.0) -
手続きオブジェクトを実行してその結果を返します。
...しくは Proc#lambda? を参照してください。
「===」は when の所に手続きを渡せるようにするためのものです。
//emlist[例][ruby]{
def sign(n)
case n
when lambda{|n| n > 0} then 1
when lambda{|n| n < 0} then -1
else 0
end
end
p sign(-4) #=> -1
p sign(0)......syntactic sugar もあります。
//emlist[例][ruby]{
fib = lambda{|n|
case n
when 0 then 0
when 1 then 1
else
fib.(n - 2) + fib.(n - 1)
end
}
fib.(10) # => 55
//}
@param arg 手続きオブジェクトに与える引数を指定します。
@raise LocalJumpError Procを生成... -
Enumerator
:: Yielder # to _ proc -> Proc (9306.0) -
Enumerator.new で使うメソッドです。
...Enumerator.new で使うメソッドです。
引数を Enumerator::Yielder#yield に渡す Proc を返します。
これは Enumerator::Yielder オブジェクトを他のメソッドにブロック引数と
して直接渡すために使えます。
//emlist[例][ruby]{
text = <<-END
Hello
こ......んにちは
END
enum = Enumerator.new do |y|
text.each_line(&y)
end
enum.each do |line|
p line
end
# => "Hello\n"
# "こんにちは\n"
//}... -
Thread
# thread _ variable _ get(key) -> object | nil (9218.0) -
引数 key で指定した名前のスレッドローカル変数を返します。
...]: Thread#[] でセットしたローカル変数(Fiber ローカル変数)と
異なり、Fiber を切り替えても同じ変数を返す事に注意してください。
例:
Thread.new {
Thread.current.thread_variable_set("foo", "bar") # スレッドローカル
Thread.current["foo"......] = "bar" # Fiber ローカル
Fiber.new {
Fiber.yield [
Thread.current.thread_variable_get("foo"), # スレッドローカル
Thread.current["foo"], # Fiber ローカル
]
}.resume
}.join.value # => ['bar', nil]
この......例の "bar" は Thread#thread_variable_get により得られ
た値で、nil はThread#[] により得られた値です。
@see Thread#thread_variable_set, Thread#[]
@see https://magazine.rubyist.net/articles/0041/0041-200Special-note.html... -
ruby 1
. 6 feature (8316.0) -
ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。
...ruby 1.6 feature
ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン
になります。
((<stable-snapshot|URL:ftp://ftp.netlab.co.jp/pub/lang/ruby/stable-snapshot.tar.gz>)) は、日々更新される安定版の最新ソースです。
== 1.6.8 (2002-12-24) ->......stable-snapshot
: 2003-01-22: errno
EAGAIN と EWOULDBLOCK が同じ値のシステムで、EWOULDBLOCK がなくなっ
ていました。現在は、このようなシステムでは、EWOULDBLOCK は、EAGAIN
として定義されています。(これは 1.6.7 とは異なる挙......end
=> -:5:in `test': uninitialized class variable @@cv in C (NameError)
from -:9
ruby 1.6.7 (2002-03-01) [i586-linux]
=> ruby 1.6.6 (2001-12-26) [i586-linux]
5
: 2002-03-03 ((<Marshal/Marshal.load>))
Marshal.load が 1.7 のメソッド Proc#yield を呼ん... -
Object
# yield _ self -> Enumerator (6344.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
...ruby]{
"my string".yield_self {|s| s.upcase } # => "MY STRING"
3.next.yield_self {|x| x**x }.to_s # => "256"
//}
値をメソッドチェインのパイプラインに次々と渡すのは良い使い方です。
//emlist[メソッドチェインのパイプライン][ruby]{
require 'open-......uri'
require 'json'
construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}
ブロックなしで呼び出されたときは Enumerator を返します。
例えば条件によって値を捨てるのに使えます。
//emlist[][ruby]{
#......条件にあうので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}
@see Object#tap... -
Fiber
# raise(exception , message = nil , backtrace = nil) -> object (6334.0) -
selfが表すファイバーが最後に Fiber.yield を呼んだ場所で例外を発生させます。
...すファイバーが最後に Fiber.yield を呼んだ場所で例外を発生させます。
Fiber.yield が呼ばれていないかファイバーがすでに終了している場合、
FiberError が発生します。
引数を渡さない場合、RuntimeError が発生します。
message 引......数を渡した場合、message 引数をメッセージとした RuntimeError
が発生します。
その他のケースでは、最初の引数は Exception か Exception
のインスタンスを返す exception メソッドを持ったオブジェクトである
必要があります。
この......@param message 例外のメッセージとなる文字列です。
@param exception 発生させる例外です。
@param backtrace 例外発生時のスタックトレースです。文字列の配列で指定します。
//emlist[例][ruby]{
f = Fiber.new { Fiber.yield }
f.resume
f.raise "Error!"... -
Exception
# backtrace _ locations -> [Thread :: Backtrace :: Location] (6312.0) -
バックトレース情報を返します。Exception#backtraceに似ていますが、 Thread::Backtrace::Location の配列を返す点が異なります。
...tion#backtraceに似ていますが、
Thread::Backtrace::Location の配列を返す点が異なります。
現状では Exception#set_backtrace によって戻り値が変化する事はあり
ません。
//emlist[例: test.rb][ruby]{
require "date"
def check_long_month(month)
return if Date......00, month, -1).day == 31
raise "#{month} is not long month"
end
def get_exception
return begin
yield
rescue => e
e
end
end
e = get_exception { check_long_month(2) }
p e.backtrace_locations
# => ["test.rb:4:in `check_long_month'", "test.rb:15:in `block in <main>'", "test.rb:9:in `ge......t_exception'", "test.rb:15:in `<main>'"]
//}
@see Exception#backtrace... -
Kernel
. # proc -> Proc (6312.0) -
与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。
...与えられたブロックから手続きオブジェクト (Proc のインスタンス)
を生成して返します。Proc.new に近い働きをします。
ブロックが指定されなければ、呼び出し元のメソッドで指定されたブロック
を手続きオブジェクトと......mlist[例][ruby]{
def foo &block
lambda(&block)
end
it = foo{p 12}
it.call #=> 12
//}
@see Proc,Proc.new
===[a:should_use_next] 手続きを中断して値を返す
手続きオブジェクトを中断して、呼出し元(呼び出しブロックでは yield、それ以外では Proc#call)......に振る舞う
ことを意図されているため、例外 LocalJumpError は発生しません。
//emlist[例][ruby]{
def foo
Proc.new { return }
end
foo.call
# => in `call': return from proc-closure (LocalJumpError)
//}
以下の表は、手続きオブジェクトの実行を上の例と... -
Kernel
. # proc { . . . } -> Proc (6312.0) -
与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。
...与えられたブロックから手続きオブジェクト (Proc のインスタンス)
を生成して返します。Proc.new に近い働きをします。
ブロックが指定されなければ、呼び出し元のメソッドで指定されたブロック
を手続きオブジェクトと......mlist[例][ruby]{
def foo &block
lambda(&block)
end
it = foo{p 12}
it.call #=> 12
//}
@see Proc,Proc.new
===[a:should_use_next] 手続きを中断して値を返す
手続きオブジェクトを中断して、呼出し元(呼び出しブロックでは yield、それ以外では Proc#call)......に振る舞う
ことを意図されているため、例外 LocalJumpError は発生しません。
//emlist[例][ruby]{
def foo
Proc.new { return }
end
foo.call
# => in `call': return from proc-closure (LocalJumpError)
//}
以下の表は、手続きオブジェクトの実行を上の例と......(Proc のインスタンス)
を生成して返します。Proc.new に近い働きをします。
また、lambda に & 引数を渡すのは推奨されません。& 引数ではなくてブロック記法で記述する必要があります。
& 引数を渡した lambda は Warning[:deprecat......emlist[例][ruby]{
def foo &block
proc(&block)
end
it = foo{p 12}
it.call #=> 12
//}
@see Proc,Proc.new
===[a:should_use_next] 手続きを中断して値を返す
手続きオブジェクトを中断して、呼出し元(呼び出しブロックでは yield、それ以外では Proc#call)
へ... -
Net
:: POP3 . foreach(address , port = nil , account , password , isapop=false) {|mail| . . . . } -> () (6306.0) -
POP セッションを開始し、 サーバ上のすべてのメールを取りだし、 個々のメールを引数としてブロックを呼びだします。
...。
port に nil を渡すと、適当なポート(通常は110、SSL利用時には 995)を
使います。
以下のコードと同様の処理をします。
require 'net/pop'
Net::POP3.start(address, port, account, password, isapop=false) {|pop|
pop.each_mail do |m|
yield m......例:
require 'net/pop'
Net::POP3.foreach('pop.example.com', 110,
'YourAccount', 'YourPassword') do |m|
file.write m.pop
m.delete if $DELETE
end
@param address POP3サーバのホスト名文字列
@param port 接続するPOP3サーバのポート番号
@param acc......ount アカウント名文字列
@param password パスワード文字列
@param isapop 真でAPOPを利用します
@raise TimeoutError 接続がタイムアウトした場合に発生します
@raise Net::POPAuthenticationError 認証に失敗した、もしくはAPOPを利用しようとした...