るりまサーチ

最速Rubyリファレンスマニュアル検索!
139件ヒット [1-100件を表示] (0.057秒)
トップページ > クエリ:p[x] > クエリ:tap[x]

別のキーワード

  1. openssl p
  2. openssl p=
  3. fileutils mkdir_p
  4. dsa p
  5. dh p

ライブラリ

クラス

モジュール

検索結果

<< 1 2 > >>

Object#tap {|x| ... } -> self (24225.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}" }
//}...
...目的です。

//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...

Socket::Constants::IFF_ISATAP (12200.0)

ISATAP interface (RFC4214)

...ISATAP interface (RFC4214)...

Socket::Constants::IFF_OVS_DATAPATH (12200.0)

device used as Open vSwitch datapath port

...device used as Open vSwitch datapath port...

Socket::IFF_ISATAP (12200.0)

ISATAP interface (RFC4214)

...ISATAP interface (RFC4214)...

Socket::IFF_OVS_DATAPATH (12200.0)

device used as Open vSwitch datapath port

...device used as Open vSwitch datapath port...

絞り込み条件を変える

Shell::Error::CantApplyMethod (12000.0)

メソッドを適用できないときに発生する例外です。

メソッドを適用できないときに発生する例外です。

Proc (6048.0)

ブロックをコンテキスト(ローカル変数のスコープやスタックフ レーム)とともにオブジェクト化した手続きオブジェクトです。

...た手続きオブジェクトです。

P
roc は ローカル変数のスコープを導入しないことを除いて
名前のない関数のように使えます。ダイナミックローカル変数は
P
roc ローカルの変数として使えます。

P
roc がローカル変数のスコー...
...][ruby]{
var = 1
$foo = Proc.new { var }
var = 2

def foo
$foo.call
end

p
foo # => 2
//}

===[a:should_use_next] 手続きを中断して値を返す

手続きオブジェクトを中断して、呼出し元(呼び出しブロックでは yield、それ以外では Proc#call)
へジャン...
...uby]{
def test_proc
f = Proc.new { return :from_proc }
f.call
return :from_method
end

def test_lambda
f = lambda { return :from_lambda }
f.call
return :from_method
end

def test_block
tap
{ return :from_block }
return :from_method
end

p
test_proc() #=> :from_proc
p
test_lambda()...

Kernel.#proc -> Proc (3248.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...
...uby]{
def test_proc
f = Proc.new { return :from_proc }
f.call
return :from_method
end

def test_lambda
f = lambda { return :from_lambda }
f.call
return :from_method
end

def test_block
tap
{ return :from_block }
return :from_method
end

p
test_proc() #=> :from_proc
p
test_lambda()...

Kernel.#proc { ... } -> Proc (3248.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...
...uby]{
def test_proc
f = Proc.new { return :from_proc }
f.call
return :from_method
end

def test_lambda
f = lambda { return :from_lambda }
f.call
return :from_method
end

def test_block
tap
{ return :from_block }
return :from_method
end

p
test_proc() #=> :from_proc
p
test_lambda()...
...(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

==...
...l block is deprecated; use the proc without lambda instead」
を出力します。

@raise ArgumentError ブロックを省略した呼び出しを行ったときに発生します。

//emlist[例][ruby]{
def foo &block
p
roc(&block)
end

it = foo{p 12}
it.call #=> 12
//}

@see Proc,Proc.new

===...

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

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

...se_next
* block
* lambda_proc
* orphan

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

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

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

def foo
$foo.call
end

p
foo # => 2
//}...
...uby]{
def test_proc
f = Proc.new { return :from_proc }
f.call
return :from_method
end

def test_lambda
f = lambda { return :from_lambda }
f.call
return :from_method
end

def test_block
tap
{ return :from_block }
return :from_method
end

p
test_proc() #=> :from_proc
p
test_lambda()...

絞り込み条件を変える

<< 1 2 > >>