種類
- インスタンスメソッド (399)
- モジュール関数 (35)
- 特異メソッド (25)
- クラス (22)
クラス
- Enumerator (77)
-
Enumerator
:: Lazy (44) -
Enumerator
:: Yielder (27) - Exception (22)
- Fiber (43)
- Object (62)
- Proc (58)
- StopIteration (11)
- Thread (11)
モジュール
- Enumerable (69)
- Kernel (35)
キーワード
- << (11)
- == (11)
- === (11)
- Fiber (11)
- Proc (11)
- [] (22)
- alive? (3)
-
backtrace
_ locations (11) - call (11)
- compact (3)
- each (44)
-
enum
_ for (44) - feed (11)
- lambda (17)
-
max
_ by (44) - new (14)
-
next
_ values (11) -
peek
_ values (11) - proc (18)
- raise (15)
- result (11)
- resume (11)
-
sort
_ by (22) - tap (7)
-
to
_ enum (44) -
to
_ proc (16) - transfer (3)
検索結果
先頭5件
-
Enumerator
:: Yielder # yield(*object) -> () (21127.0) -
Enumerator.new で使うメソッドです。
...ブジェクトの 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 (18121.0) -
現在のファイバーの親にコンテキストを切り替えます。
... 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) -> () (18121.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) #=> 0
p s......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 (9214.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"
//}... -
Object
# to _ proc -> Proc (6214.0) -
オブジェクトの Proc への暗黙の変換が必要なときに内部で呼ばれます。 デフォルトでは定義されていません。
...オブジェクトの Proc への暗黙の変換が必要なときに内部で呼ばれます。
デフォルトでは定義されていません。
説明のためここに記載してありますが、
このメソッドは実際には Object クラスには定義されていません。
必要......に応じてサブクラスで定義すべきものです。
//emlist[][ruby]{
def doing
yield
end
class Foo
def to_proc
Proc.new{p 'ok'}
end
end
it = Foo.new
doing(&it) #=> "ok"
//}... -
Enumerator
# peek _ values -> Array (6162.0) -
Enumerator#next_values のように「次」のオブジェクトを 配列で返しますが、列挙状態を変化させません。
...StopIteration 例外を発生します。
このメソッドは Enumerator#next_values と同様
yield
と
yield nil
を区別するために使えます。
//emlist[例][ruby]{
o = Object.new
def o.each
yield
yield 1
yield 1, 2
end
e = o.to_enum
p e.peek_values #=> []
e.next
p e.peek......_values #=> [1]
p e.peek_values #=> [1]
e.next
p e.peek_values #=> [1, 2]
e.next
p e.peek_values # raises StopIteration
//}
@raise StopIteration 列挙状態が既に最後へ到達しているとき
@see Enumerator#next, Enumerator#next_values, Enumerator#peek_values... -
Enumerable
# compact -> Array (6126.0) -
self から nil を取り除いた配列を生成して返します。
...self から nil を取り除いた配列を生成して返します。
//emlist[][ruby]{
def with_nils
yield 1
yield 2
yield nil
yield 3
end
to_enum(:with_nils).compact # => [1, 2, 3]
//}
@see Array#compact... -
Object
# tap {|x| . . . } -> self (6108.0) -
self を引数としてブロックを評価し、self を返します。
...目的です。
//emlist[][ruby]{
(1..10) .tap {|x| puts "original: #{x}" }
.to_a .tap {|x| puts "array: #{x}" }
.select {|x| x.even? } .tap {|x| puts "evens: #{x}" }
.map {|x| x*x } .tap {|x| puts "squares: #{x}" }
//}
@see Object#yield_self... -
Proc (6050.0)
-
ブロックをコンテキスト(ローカル変数のスコープやスタックフ レーム)とともにオブジェクト化した手続きオブジェクトです。
...た手続きオブジェクトです。
Proc は ローカル変数のスコープを導入しないことを除いて
名前のない関数のように使えます。ダイナミックローカル変数は
Proc ローカルの変数として使えます。
Proc がローカル変数のスコー......][ruby]{
var = 1
$foo = Proc.new { var }
var = 2
def foo
$foo.call
end
p foo # => 2
//}
===[a:should_use_next] 手続きを中断して値を返す
手続きオブジェクトを中断して、呼出し元(呼び出しブロックでは yield、それ以外では Proc#call)
へジャン......[ruby]{
def foo
f = Proc.new{
next 1
2 # この行に到達することはない
}
end
p foo().call #=> 1
//}
===[a:block] Proc オブジェクトをブロック付きメソッド呼び出しに使う
ブロック付きメソッドに対して Proc オブジェク... -
Kernel
. # proc -> Proc (3250.0) -
与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。
...与えられたブロックから手続きオブジェクト (Proc のインスタンス)
を生成して返します。Proc.new に近い働きをします。
ブロックが指定されなければ、呼び出し元のメソッドで指定されたブロック
を手続きオブジェクトと......ied to create Proc object without a block」
が出力され、Ruby 2.7 では
ArgumentError (tried to create Proc object without a block)
が発生します。
ブロックを指定しない proc は、Ruby 2.7 では
$VERBOSE = true のときには警告メッセージ
「warning: Capturing the g......iven block using Proc.new is deprecated; use `&block` instead」
が出力され、Ruby 3.0 では
ArgumentError (tried to create Proc object without a block)
が発生します。
@raise ArgumentError スタック上にブロックがないのにブロックを省略した呼び出しを行った... -
Kernel
. # proc { . . . } -> Proc (3250.0) -
与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。
...与えられたブロックから手続きオブジェクト (Proc のインスタンス)
を生成して返します。Proc.new に近い働きをします。
ブロックが指定されなければ、呼び出し元のメソッドで指定されたブロック
を手続きオブジェクトと......ied to create Proc object without a block」
が出力され、Ruby 2.7 では
ArgumentError (tried to create Proc object without a block)
が発生します。
ブロックを指定しない proc は、Ruby 2.7 では
$VERBOSE = true のときには警告メッセージ
「warning: Capturing the g......iven block using Proc.new is deprecated; use `&block` instead」
が出力され、Ruby 3.0 では
ArgumentError (tried to create Proc object without a block)
が発生します。
@raise ArgumentError スタック上にブロックがないのにブロックを省略した呼び出しを行った......(Proc のインスタンス)
を生成して返します。Proc.new に近い働きをします。
また、lambda に & 引数を渡すのは推奨されません。& 引数ではなくてブロック記法で記述する必要があります。
& 引数を渡した lambda は Warning[:deprecat......block is deprecated; use the proc without lambda instead」
を出力します。
@raise ArgumentError ブロックを省略した呼び出しを行ったときに発生します。
//emlist[例][ruby]{
def foo &block
lambda(&block)
end
it = foo{p 12}
it.call #=> 12
//}
@see Proc,Proc.new
==......ロックでは yield、それ以外では Proc#call)
へジャンプし値を返すには next を使います。break や return ではありません。
//emlist[例][ruby]{
def foo
f = Proc.new{
next 1
2 # この行に到達することはない
}
end
p foo().call......l block is deprecated; use the proc without lambda instead」
を出力します。
@raise ArgumentError ブロックを省略した呼び出しを行ったときに発生します。
//emlist[例][ruby]{
def foo &block
proc(&block)
end
it = foo{p 12}
it.call #=> 12
//}
@see Proc,Proc.new
===... -
Proc
. new -> Proc (3120.0) -
ブロックをコンテキストとともにオブジェクト化して返します。
...2.7 では
$VERBOSE = true のときには警告メッセージ
「warning: Capturing the given block using Proc.new is deprecated; use `&block` instead」
が出力され、Ruby 3.0 では
ArgumentError (tried to create Proc object without a block)
が発生します。
ブロックを指定しな......ければ、このメソッドを呼び出したメソッドが
ブロックを伴うときに、それを Proc オブジェクトとして生成して返します。
ただし、ブロックを指定しない呼び出しは推奨されていません。呼び出し元のメソッドで指定され......しを行ったときに発生します。
//emlist[例][ruby]{
def foo
pr = Proc.new
pr.call(1)
end
foo {|arg| p arg }
# => 1
//}
これは以下と同じです。
//emlist[例][ruby]{
def foo
yield(1)
end
foo {|arg| p arg }
# => 1
//}
呼び出し元のメソッドがブロックを伴...