るりまサーチ

最速Rubyリファレンスマニュアル検索!
286件ヒット [1-100件を表示] (0.016秒)

別のキーワード

  1. _builtin to_proc
  2. _builtin proc
  3. proc curry
  4. httpserver mount_proc
  5. readline completion_proc

検索結果

<< 1 2 3 > >>

Proc (38216.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)
へジャン...
...o
f = Proc.new{
next 1
2 # この行に到達することはない
}
end

p foo().call #=> 1
//}

===[a:block] Proc オブジェクトをブロック付きメソッド呼び出しに使う

ブロック付きメソッドに対して Proc オブジェクトを `&' を...

Proc#ruby2_keywords -> proc (21189.0)

Marks the proc as passing keywords through a normal argument splat. This should only be called on procs that accept an argument splat (`*args`) but not explicit keywords or a keyword splat. It marks the proc such that if the proc is called with keyword arguments, the final hash argument is marked with a special flag such that if it is the final element of a normal argument splat to another method call, and that method call does not include explicit keywords or a keyword splat, the final element is interpreted as keywords. In other words, keywords will be passed through the proc to other methods.

...Marks the proc as passing keywords through a normal argument splat. This
should only be called on procs that accept an argument splat (`*args`)
but not explicit keywords or a keyword splat. It marks the proc such
that if the proc is called with keyword arguments, the final hash
argument is marked...
...ds or a keyword splat, the
final element is interpreted as keywords. In other words, keywords will
be passed through the proc to other methods.

This should only be used for procs that delegate keywords to another
method, and only for backwards compatibility with Ruby versions before
2.7.

This met...
...check that the proc responds to this method before calling
it. Also, be aware that if this method is removed, the behavior of the
proc
will change so that it does not pass through keywords.

//emlist[][ruby]{
module Mod
foo = ->(meth, *args, &block) do
send(:"do_#{meth}", *args, &block)
end...

Proc#lambda? -> bool (21174.0)

手続きオブジェクトの引数の取扱が厳密であるならば true を返します。

...list[例][ruby]{
# lambda で生成した Proc オブジェクトでは true
lambda{}.lambda? # => true
# proc で生成した Proc オブジェクトでは false
proc
{}.lambda? # => false
# Proc.new で生成した Proc オブジェクトでは false
Proc
.new{}.lambda? # => false

# 以下、lam...
...無視する
proc
{|a,b| [a,b]}.call(1,2,3) # => [1,2]
# 足りない引数には nil が渡される
proc
{|a,b| [a,b]}.call(1) # => [1, nil]
# 配列1つだと展開される
proc
{|a,b| [a,b]}.call([1,2]) # => [1,2]
# lambdaの場合これらはすべて ArgumentError となる

# &が付いた仮...
...成される Proc は lambda? が偽となる
def n(&b) b.lambda? end
n {} # => false

# &が付いた実引数によるものは、lambda?が元の Procオブジェクトから
# 引き継がれる
lambda(&lambda {}).lambda? #=> true
proc
(&lambda {}).lambda? #=> true
Proc
.new(&lambda {}).lamb...

Proc.new -> Proc (21162.0)

ブロックをコンテキストとともにオブジェクト化して返します。

...OSE = 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)
が発生します。

ブロックを指定しなければ、こ...
...
を得たい場合は明示的に & 引数でうけるべきです。

@raise ArgumentError スタック上にブロックがないのにブロックを省略した呼び出しを行ったときに発生します。

//emlist[例][ruby]{
def foo
pr = Proc.new
pr.call(1)
end
foo {|arg| p arg...
...entError が発生します。

//emlist[例][ruby]{
def foo
Proc
.new
end
foo
# => -:2:in `new': tried to create Proc object without a block (ArgumentError)
# from -:2:in `foo'
# from -:4:in `<main>'
//}

Proc
.new は、Proc#initialize が定義されていれば
オブジェクト...

Proc.new { ... } -> Proc (21162.0)

ブロックをコンテキストとともにオブジェクト化して返します。

...OSE = 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)
が発生します。

ブロックを指定しなければ、こ...
...
を得たい場合は明示的に & 引数でうけるべきです。

@raise ArgumentError スタック上にブロックがないのにブロックを省略した呼び出しを行ったときに発生します。

//emlist[例][ruby]{
def foo
pr = Proc.new
pr.call(1)
end
foo {|arg| p arg...
...entError が発生します。

//emlist[例][ruby]{
def foo
Proc
.new
end
foo
# => -:2:in `new': tried to create Proc object without a block (ArgumentError)
# from -:2:in `foo'
# from -:4:in `<main>'
//}

Proc
.new は、Proc#initialize が定義されていれば
オブジェクト...

絞り込み条件を変える

Process::Status#&(other) -> Integer (21122.0)

self.to_i & other と同じです。 このメソッドは後方互換性のためにあります。

...self.to_i & other と同じです。
このメソッドは後方互換性のためにあります。

@param other 自身との & 演算をしたい整数を指定します。...

Proc#parameters(lambda: nil) -> [object] (21052.0)

Proc オブジェクトの引数の情報を返します。

...Proc オブジェクトの引数の情報を返します。

Proc
オブジェクトが引数を取らなければ空の配列を返します。引数を取る場合は、配列の配列を返し、
各配列の要素は引数の種類に対応した以下のような Symbol と、引数名を表す...
...ck
&
で指定されたブロック引数

@param lambda true なら lambda として扱ったとき、false なら lambda ではない Proc として
扱ったときの引数の情報を返します。

//emlist[例][ruby]{
prc = lambda{|x, y=42, *other, k_x:, k_y: 42, **k_other, &b|...
..._other], [:block, :b
//}

//emlist[lambda: の例][ruby]{
prc = proc{|x, y=42, *other|}
p prc.parameters # => x], [:opt, :y], [:rest, :other
prc = lambda{|x, y=42, *other|}
p prc.parameters # => x], [:opt, :y], [:rest, :other
prc = proc{|x, y=42, *other|}
p prc.parameters(lambda: true) # => x], [...

Proc#parameters -> [object] (21034.0)

Proc オブジェクトの引数の情報を返します。

...Proc オブジェクトの引数の情報を返します。

Proc
オブジェクトが引数を取らなければ空の配列を返します。引数を取る場合は、配列の配列を返し、
各配列の要素は引数の種類に対応した以下のような Symbol と、引数名を表す...
...ワード引数
: :keyrest
** で指定された残りのキーワード引数
: :block
&
で指定されたブロック引数


//emlist[例][ruby]{
prc = lambda{|x, y=42, *other, k_x:, k_y: 42, **k_other, &b|}
prc.parameters #=> x], [:opt, :y], [:rest, :other], [:keyreq, :k_x], [:key, :k_y], [:k...

Symbol#to_proc -> Proc (6272.0)

self に対応する Proc オブジェクトを返します。

...self に対応する Proc オブジェクトを返します。

生成される Proc オブジェクトを呼びだす(Proc#call)と、
Proc
#callの第一引数をレシーバとして、 self という名前のメソッドを
残りの引数を渡して呼びだします。


//emlist[明示的に...
...][ruby]{
:to_i.to_proc["ff", 16] # => 255 ← "ff".to_i(16)と同じ
//}

//emlist[暗黙に呼ばれる例][ruby]{
# メソッドに & とともにシンボルを渡すと
# to_proc が呼ばれて Proc 化され、
# それがブロックとして渡される。
(1..3).collect(&:to_s) # => ["1",...
..."2", "3"]
(1..3).select(&:odd?) # => [1, 3]
//}

@see d:spec/call#block...
...対応する Proc オブジェクトを返します。

生成される Proc オブジェクトを呼びだす(Proc#call)と、
Proc
#callの第一引数をレシーバとして、 self という名前のメソッドを
残りの引数を渡して呼びだします。

生成される Proc オブジ...
...by]{
:object_id.to_proc.lambda? # => true
//}

//emlist[明示的に呼ぶ例][ruby]{
:to_i.to_proc["ff", 16] # => 255 ← "ff".to_i(16)と同じ
//}

//emlist[暗黙に呼ばれる例][ruby]{
# メソッドに & とともにシンボルを渡すと
# to_proc が呼ばれて Proc 化され、
# そ...
...れがブロックとして渡される。
(1..3).collect(&:to_s) # => ["1", "2", "3"]
(1..3).select(&:odd?) # => [1, 3]
//}

@see d:spec/call#block...

Kernel.#proc -> Proc (3484.0)

与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。

...与えられたブロックから手続きオブジェクト (Proc のインスタンス)
を生成して返します。Proc.new に近い働きをします。

ブロックが指定されなければ、呼び出し元のメソッドで指定されたブロック
を手続きオブジェクトと...
...い場合は明示的に & 引数でうけるべきです。

ブロックを指定しない lambda は Ruby 2.6 までは警告メッセージ
「warning: tried 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 given block using Proc.new is deprecated; use `&block` instead」
が出力され、Ruby 3.0 では
ArgumentError (tried to create Proc object without a block)
が発...

絞り込み条件を変える

Kernel.#proc { ... } -> Proc (3484.0)

与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。

...与えられたブロックから手続きオブジェクト (Proc のインスタンス)
を生成して返します。Proc.new に近い働きをします。

ブロックが指定されなければ、呼び出し元のメソッドで指定されたブロック
を手続きオブジェクトと...
...い場合は明示的に & 引数でうけるべきです。

ブロックを指定しない lambda は Ruby 2.6 までは警告メッセージ
「warning: tried 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 given block using Proc.new is deprecated; use `&block` instead」
が出力され、Ruby 3.0 では
ArgumentError (tried to create Proc object without a block)
が発...

Kernel.#proc -> Proc (3483.0)

与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。

...与えられたブロックから手続きオブジェクト (Proc のインスタンス)
を生成して返します。Proc.new に近い働きをします。

ブロックが指定されなければ、呼び出し元のメソッドで指定されたブロック
を手続きオブジェクトと...
...い場合は明示的に & 引数でうけるべきです。

ブロックを指定しない lambda は Ruby 2.6 までは警告メッセージ
「warning: tried 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 given block using Proc.new is deprecated; use `&block` instead」
が出力され、Ruby 3.0 では
ArgumentError (tried to create Proc object without a block)
が発...

Kernel.#proc { ... } -> Proc (3483.0)

与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。

...与えられたブロックから手続きオブジェクト (Proc のインスタンス)
を生成して返します。Proc.new に近い働きをします。

ブロックが指定されなければ、呼び出し元のメソッドで指定されたブロック
を手続きオブジェクトと...
...い場合は明示的に & 引数でうけるべきです。

ブロックを指定しない lambda は Ruby 2.6 までは警告メッセージ
「warning: tried 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 given block using Proc.new is deprecated; use `&block` instead」
が出力され、Ruby 3.0 では
ArgumentError (tried to create Proc object without a block)
が発...
...きオブジェクト (Proc のインスタンス)
を生成して返します。Proc.new に近い働きをします。


また、lambda に & 引数を渡すのは推奨されません。& 引数ではなくてブロック記法で記述する必要があります。

&
引数を渡した lambda...
...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

===[a:should...
...では Proc#call)
へジャンプし値を返すには next を使います。break や return ではありません。


//emlist[例][ruby]{
def foo
f = Proc.new{
next 1
2 # この行に到達することはない
}
end

p foo().call #=> 1
//}

===[a:block] Proc...
...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

===[a:should_...

手続きオブジェクトの挙動の詳細 (3226.0)

手続きオブジェクトの挙動の詳細 * def * should_use_next * block * lambda_proc * orphan

...e_next
* block
* lambda_proc
* orphan

===[a:def] 手続きオブジェクトとは

手続きオブジェクトとはブロックをコンテキスト(ローカル変数のスコープやスタックフレーム)と
ともにオブジェクトにしたものです。Proc クラスのインスタ...
...ローカル変数を参照できます。
Proc
オブジェクトがローカル変数のスコープを保持していることは以下の例で変数 var を
参照できていることからわかります。

//emlist[例][ruby]{
var = 1
$foo = Proc.new { var }
var = 2

def foo
$foo.call
end...
...o
f = Proc.new{
next 1
2 # この行に到達することはない
}
end

p foo().call #=> 1
//}

===[a:block] Proc オブジェクトをブロック付きメソッド呼び出しに使う

ブロック付きメソッドに対して Proc オブジェクトを `&' を...
<< 1 2 3 > >>