クラス
- Enumerator (84)
-
Enumerator
:: Lazy (48) -
Enumerator
:: Yielder (30) - Exception (24)
- Fiber (54)
- Object (98)
- Pathname (39)
- Proc (48)
- StopIteration (12)
- Thread (24)
モジュール
- Enumerable (100)
キーワード
- << (12)
- == (12)
- === (12)
- [] (24)
- alive? (12)
-
backtrace
_ locations (12) - call (12)
- compact (4)
- each (48)
-
each
_ entry (39) -
enum
_ for (48) - feed (12)
- find (24)
-
max
_ by (48) -
next
_ values (12) -
peek
_ values (12) - raise (18)
- result (12)
- resume (12)
-
sort
_ by (24) - tap (8)
- then (14)
-
thread
_ variable _ get (12) -
to
_ enum (48) -
to
_ proc (18) - transfer (12)
-
yield
_ self (16)
検索結果
先頭5件
-
Fiber
# alive? -> bool (19.0) -
ファイバーが「生きている」時、真を返します。
...ume されていない
* ブロック内の評価が終了していない (Fiber.yield が呼ばれていない)
//emlist[例:][ruby]{
fr = Fiber.new{
Fiber.yield
"a"
}
p fr.alive? # => true
fr.resume # Fiber.yieldで戻ってくる
p fr.alive? # => true
fr.resume # ブロック内の評価... -
Pathname
# each _ entry -> Enumerator (17.0) -
Dir.foreach(self.to_s) {|f| yield Pathname.new(f) } と同じです。
...Dir.foreach(self.to_s) {|f| yield Pathname.new(f) } と同じです。
ブロックを省略した場合は Enumerator を返します。
//emlist[例][ruby]{
require "pathname"
Pathname("/usr/local").each_entry {|f| p f }
# => #<Pathname:.>
# => #<Pathname:..>
# => #<Pathname:bin>
# => #<Pathna... -
Pathname
# each _ entry {|pathname| . . . } -> nil (17.0) -
Dir.foreach(self.to_s) {|f| yield Pathname.new(f) } と同じです。
...Dir.foreach(self.to_s) {|f| yield Pathname.new(f) } と同じです。
//emlist[例][ruby]{
require "pathname"
Pathname("/usr/local").each_entry {|f| p f }
# => #<Pathname:.>
# => #<Pathname:..>
# => #<Pathname:bin>
# => #<Pathname:etc>
# => #<Pathname:include>
# => #<Pathname:lib>
# => #<Pathna......Dir.foreach(self.to_s) {|f| yield Pathname.new(f) } と同じです。
ブロックを省略した場合は Enumerator を返します。
//emlist[例][ruby]{
require "pathname"
Pathname("/usr/local").each_entry {|f| p f }
# => #<Pathname:.>
# => #<Pathname:..>
# => #<Pathname:bin>
# => #<Pathna... -
Enumerable
# each _ entry -> Enumerator (13.0) -
ブロックを各要素に一度ずつ適用します。
...が渡された場合はブロックには配列として渡されます。
//emlist[例][ruby]{
class Foo
include Enumerable
def each
yield 1
yield 1,2
end
end
Foo.new.each_entry{|o| print o, " -- "}
# => 1 -- [1, 2] --
//}
ブロックを省略した場合は Enumerator が返さ... -
Enumerable
# each _ entry {|obj| block} -> self (13.0) -
ブロックを各要素に一度ずつ適用します。
...が渡された場合はブロックには配列として渡されます。
//emlist[例][ruby]{
class Foo
include Enumerable
def each
yield 1
yield 1,2
end
end
Foo.new.each_entry{|o| print o, " -- "}
# => 1 -- [1, 2] --
//}
ブロックを省略した場合は Enumerator が返さ... -
Fiber
# resume(*arg = nil) -> object (13.0) -
自身が表すファイバーへコンテキストを切り替えます。 自身は resume を呼んだファイバーの子となります。
...m arg self が表すファイバーに渡したいオブジェクトを指定します。
@return コンテキストの切り替えの際に Fiber.yield に与えられた引数
を返します。ブロックの終了まで実行した場合はブロックの評価結果
を返し......また、Fiber#transfer を呼び出した後に resume を
呼び出した場合に発生します。
//emlist[例:][ruby]{
f = Fiber.new do
Fiber.yield(:hoge)
:fuga
end
p f.resume() #=> :hoge
p f.resume() #=> :fuga
p f.resume() #=> FiberError: dead fiber called
//}... -
Thread
# [](name) -> object | nil (13.0) -
name に対応したスレッドに固有のデータを取り出します。 name に対応するスレッド固有データがなければ nil を返し ます。
...:name] = newvalue
yield
ensure
Thread.current[:name] = oldvalue
end
end
//}
この関数に与えるブロックがFiberを切り替える場合は動的スコープとしては
正しく動作しません。
//emlist[][ruby]{
f = Fiber.new {
meth(1) {
Fiber.yield
}
}
meth(2) {... -
Enumerable
# max _ by -> Enumerator (7.0) -
各要素を順番にブロックに渡して実行し、 その評価結果を <=> で比較して、 最大であった値に対応する元の要素、もしくは最大の n 要素が降順で入った配列を返します。
...ng with a reservoir
# Information Processing Letters
# Volume 97, Issue 5 (16 March 2006)
def wsample(n)
self.max_by(n) {|v| rand ** (1.0/yield(v)) }
end
end
e = (-20..20).to_a*10000
a = e.wsample(20000) {|x|
Math.exp(-(x/5.0)**2) # normal distribution
}
# a is 20000 samples from e.
p... -
Enumerable
# max _ by {|item| . . . } -> object | nil (7.0) -
各要素を順番にブロックに渡して実行し、 その評価結果を <=> で比較して、 最大であった値に対応する元の要素、もしくは最大の n 要素が降順で入った配列を返します。
...ng with a reservoir
# Information Processing Letters
# Volume 97, Issue 5 (16 March 2006)
def wsample(n)
self.max_by(n) {|v| rand ** (1.0/yield(v)) }
end
end
e = (-20..20).to_a*10000
a = e.wsample(20000) {|x|
Math.exp(-(x/5.0)**2) # normal distribution
}
# a is 20000 samples from e.
p... -
Enumerable
# max _ by(n) -> Enumerator (7.0) -
各要素を順番にブロックに渡して実行し、 その評価結果を <=> で比較して、 最大であった値に対応する元の要素、もしくは最大の n 要素が降順で入った配列を返します。
...ng with a reservoir
# Information Processing Letters
# Volume 97, Issue 5 (16 March 2006)
def wsample(n)
self.max_by(n) {|v| rand ** (1.0/yield(v)) }
end
end
e = (-20..20).to_a*10000
a = e.wsample(20000) {|x|
Math.exp(-(x/5.0)**2) # normal distribution
}
# a is 20000 samples from e.
p...