種類
- インスタンスメソッド (37)
- モジュール関数 (35)
- 文書 (11)
- クラス (11)
ライブラリ
- ビルトイン (83)
クラス
- Object (37)
モジュール
- Kernel (35)
キーワード
- Proc (11)
- lambda (17)
- proc (18)
- then (12)
-
yield
_ self (14) - 手続きオブジェクトの挙動の詳細 (11)
検索結果
先頭5件
-
Object
# tap {|x| . . . } -> self (18225.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... -
Kernel
. # lambda -> Proc (112.0) -
与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。
..._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() #=> :from_method
p test_block() #=> :from_block......、例外 LocalJumpError は発生しません。
//emlist[例][ruby]{
def foo
Proc.new { return }
end
foo.call
# => in `call': return from proc-closure (LocalJumpError)
//}
以下の表は、手続きオブジェクトの実行を上の例と同じように、手続きオブジェクトが定... -
Kernel
. # lambda { . . . } -> Proc (112.0) -
与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。
..._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() #=> :from_method
p test_block() #=> :from_block......、例外 LocalJumpError は発生しません。
//emlist[例][ruby]{
def foo
Proc.new { return }
end
foo.call
# => in `call': return from proc-closure (LocalJumpError)
//}
以下の表は、手続きオブジェクトの実行を上の例と同じように、手続きオブジェクトが定... -
Kernel
. # proc -> Proc (112.0) -
与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。
..._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() #=> :from_method
p test_block() #=> :from_block......、例外 LocalJumpError は発生しません。
//emlist[例][ruby]{
def foo
Proc.new { return }
end
foo.call
# => in `call': return from proc-closure (LocalJumpError)
//}
以下の表は、手続きオブジェクトの実行を上の例と同じように、手続きオブジェクトが定... -
Kernel
. # proc { . . . } -> Proc (112.0) -
与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。
..._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() #=> :from_method
p test_block() #=> :from_block......、例外 LocalJumpError は発生しません。
//emlist[例][ruby]{
def foo
Proc.new { return }
end
foo.call
# => in `call': return from proc-closure (LocalJumpError)
//}
以下の表は、手続きオブジェクトの実行を上の例と同じように、手続きオブジェクトが定... -
Object
# then -> Enumerator (112.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
...ンのパイプラインに次々と渡すのは良い使い方です。
//emlist[メソッドチェインのパイプライン][ruby]{
require 'open-uri'
require 'json'
construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}
ブロック......返します。
例えば条件によって値を捨てるのに使えます。
//emlist[][ruby]{
# 条件にあうので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}
@see Object#tap... -
Object
# then {|x| . . . } -> object (112.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
...ンのパイプラインに次々と渡すのは良い使い方です。
//emlist[メソッドチェインのパイプライン][ruby]{
require 'open-uri'
require 'json'
construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}
ブロック......返します。
例えば条件によって値を捨てるのに使えます。
//emlist[][ruby]{
# 条件にあうので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}
@see Object#tap... -
Object
# yield _ self -> Enumerator (112.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
...ンのパイプラインに次々と渡すのは良い使い方です。
//emlist[メソッドチェインのパイプライン][ruby]{
require 'open-uri'
require 'json'
construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}
ブロック......返します。
例えば条件によって値を捨てるのに使えます。
//emlist[][ruby]{
# 条件にあうので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}
@see Object#tap... -
Object
# yield _ self {|x| . . . } -> object (112.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
...ンのパイプラインに次々と渡すのは良い使い方です。
//emlist[メソッドチェインのパイプライン][ruby]{
require 'open-uri'
require 'json'
construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}
ブロック......返します。
例えば条件によって値を捨てるのに使えます。
//emlist[][ruby]{
# 条件にあうので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}
@see Object#tap... -
Proc (12.0)
-
ブロックをコンテキスト(ローカル変数のスコープやスタックフ レーム)とともにオブジェクト化した手続きオブジェクトです。
..._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() #=> :from_method
p test_block() #=> :from_block......、例外 LocalJumpError は発生しません。
//emlist[例][ruby]{
def foo
Proc.new { return }
end
foo.call
# => in `call': return from proc-closure (LocalJumpError)
//}
以下の表は、手続きオブジェクトの実行を上の例と同じように、手続きオブジェクトが定... -
手続きオブジェクトの挙動の詳細 (12.0)
-
手続きオブジェクトの挙動の詳細 * def * should_use_next * block * lambda_proc * orphan
..._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() #=> :from_method
p test_block() #=> :from_block......、例外 LocalJumpError は発生しません。
//emlist[例][ruby]{
def foo
Proc.new { return }
end
foo.call
# => in `call': return from proc-closure (LocalJumpError)
//}
以下の表は、手続きオブジェクトの実行を上の例と同じように、手続きオブジェクトが定...