別のキーワード
種類
- インスタンスメソッド (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 (18362.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... -
Object
# then {|x| . . . } -> object (238.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
...ext.then {|x| x**x }.to_s # => "256"
"my string".yield_self {|s| s.upcase } # => "MY STRING"
//}
値をメソッドチェインのパイプラインに次々と渡すのは良い使い方です。
//emlist[メソッドチェインのパイプライン][ruby]{
require 'open-uri'
requi......re 'json'
construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}
ブロックなしで呼び出されたときは Enumerator を返します。
例えば条件によって値を捨てるのに使えます。
//emlist[][ruby]{
# 条件に......あうので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}
@see Object#tap... -
Object
# yield _ self {|x| . . . } -> object (238.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
...ng".yield_self {|s| s.upcase } # => "MY STRING"
3.next.yield_self {|x| x**x }.to_s # => "256"
//}
値をメソッドチェインのパイプラインに次々と渡すのは良い使い方です。
//emlist[メソッドチェインのパイプライン][ruby]{
require 'open-uri'
require 'j......son'
construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}
ブロックなしで呼び出されたときは Enumerator を返します。
例えば条件によって値を捨てるのに使えます。
//emlist[][ruby]{
# 条件にあ......うので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}
@see Object#tap......ext.then {|x| x**x }.to_s # => "256"
"my string".yield_self {|s| s.upcase } # => "MY STRING"
//}
値をメソッドチェインのパイプラインに次々と渡すのは良い使い方です。
//emlist[メソッドチェインのパイプライン][ruby]{
require 'open-uri'
requi......re 'json'
construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}
ブロックなしで呼び出されたときは Enumerator を返します。
例えば条件によって値を捨てるのに使えます。
//emlist[][ruby]{
# 条件に......あうので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}
@see Object#tap... -
Object
# then -> Enumerator (138.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
...ext.then {|x| x**x }.to_s # => "256"
"my string".yield_self {|s| s.upcase } # => "MY STRING"
//}
値をメソッドチェインのパイプラインに次々と渡すのは良い使い方です。
//emlist[メソッドチェインのパイプライン][ruby]{
require 'open-uri'
requi......re 'json'
construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}
ブロックなしで呼び出されたときは Enumerator を返します。
例えば条件によって値を捨てるのに使えます。
//emlist[][ruby]{
# 条件に......あうので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}
@see Object#tap... -
Object
# yield _ self -> Enumerator (138.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
...ng".yield_self {|s| s.upcase } # => "MY STRING"
3.next.yield_self {|x| x**x }.to_s # => "256"
//}
値をメソッドチェインのパイプラインに次々と渡すのは良い使い方です。
//emlist[メソッドチェインのパイプライン][ruby]{
require 'open-uri'
require 'j......son'
construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}
ブロックなしで呼び出されたときは Enumerator を返します。
例えば条件によって値を捨てるのに使えます。
//emlist[][ruby]{
# 条件にあ......うので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}
@see Object#tap......ext.then {|x| x**x }.to_s # => "256"
"my string".yield_self {|s| s.upcase } # => "MY STRING"
//}
値をメソッドチェインのパイプラインに次々と渡すのは良い使い方です。
//emlist[メソッドチェインのパイプライン][ruby]{
require 'open-uri'
requi......re 'json'
construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}
ブロックなしで呼び出されたときは Enumerator を返します。
例えば条件によって値を捨てるのに使えます。
//emlist[][ruby]{
# 条件に......あうので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}
@see Object#tap... -
Kernel
. # lambda -> Proc (124.0) -
与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。
...数の数が違っていてもエラーにならない][ruby]{
b = Proc.new{|a,b,c|
p a,b,c
}
b.call(2, 4)
#=> 2
4
nil
//}
//emlist[lambda は引数の数が違うとエラーになる][ruby]{
b = lambda{|a,b,c|
p a,b,c
}
b.call(2, 4)
#=> wrong number of arguments (2 for 3) (ArgumentErr......_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)
//}
以下の表は、手続きオブジェクトの実行を上の例と同じように、手続きオブジェクトが定......数の数が違っていてもエラーにならない][ruby]{
b = Proc.new{|a,b,c|
p a,b,c
}
b.call(2, 4)
#=> 2
4
nil
//}
//emlist[lambda は引数の数が違うとエラーになる][ruby]{
b = lambda{|a,b,c|
p a,b,c
}
b.call(2, 4)
# => wrong number of arguments (given 2, expected 3)... -
Kernel
. # lambda { . . . } -> Proc (124.0) -
与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。
...数の数が違っていてもエラーにならない][ruby]{
b = Proc.new{|a,b,c|
p a,b,c
}
b.call(2, 4)
#=> 2
4
nil
//}
//emlist[lambda は引数の数が違うとエラーになる][ruby]{
b = lambda{|a,b,c|
p a,b,c
}
b.call(2, 4)
#=> wrong number of arguments (2 for 3) (ArgumentErr......_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)
//}
以下の表は、手続きオブジェクトの実行を上の例と同じように、手続きオブジェクトが定......数の数が違っていてもエラーにならない][ruby]{
b = Proc.new{|a,b,c|
p a,b,c
}
b.call(2, 4)
#=> 2
4
nil
//}
//emlist[lambda は引数の数が違うとエラーになる][ruby]{
b = lambda{|a,b,c|
p a,b,c
}
b.call(2, 4)
# => wrong number of arguments (given 2, expected 3)... -
Kernel
. # proc -> Proc (124.0) -
与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。
...数の数が違っていてもエラーにならない][ruby]{
b = Proc.new{|a,b,c|
p a,b,c
}
b.call(2, 4)
#=> 2
4
nil
//}
//emlist[lambda は引数の数が違うとエラーになる][ruby]{
b = lambda{|a,b,c|
p a,b,c
}
b.call(2, 4)
#=> wrong number of arguments (2 for 3) (ArgumentErr......_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)
//}
以下の表は、手続きオブジェクトの実行を上の例と同じように、手続きオブジェクトが定......数の数が違っていてもエラーにならない][ruby]{
b = Proc.new{|a,b,c|
p a,b,c
}
b.call(2, 4)
#=> 2
4
nil
//}
//emlist[lambda は引数の数が違うとエラーになる][ruby]{
b = lambda{|a,b,c|
p a,b,c
}
b.call(2, 4)
# => wrong number of arguments (given 2, expected 3)... -
Kernel
. # proc { . . . } -> Proc (124.0) -
与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。
...数の数が違っていてもエラーにならない][ruby]{
b = Proc.new{|a,b,c|
p a,b,c
}
b.call(2, 4)
#=> 2
4
nil
//}
//emlist[lambda は引数の数が違うとエラーになる][ruby]{
b = lambda{|a,b,c|
p a,b,c
}
b.call(2, 4)
#=> wrong number of arguments (2 for 3) (ArgumentErr......_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)
//}
以下の表は、手続きオブジェクトの実行を上の例と同じように、手続きオブジェクトが定......数の数が違っていてもエラーにならない][ruby]{
b = Proc.new{|a,b,c|
p a,b,c
}
b.call(2, 4)
#=> 2
4
nil
//}
//emlist[lambda は引数の数が違うとエラーになる][ruby]{
b = lambda{|a,b,c|
p a,b,c
}
b.call(2, 4)
# => wrong number of arguments (given 2, expected 3)... -
Proc (24.0)
-
ブロックをコンテキスト(ローカル変数のスコープやスタックフ レーム)とともにオブジェクト化した手続きオブジェクトです。
...数の数が違っていてもエラーにならない][ruby]{
b = Proc.new{|a,b,c|
p a,b,c
}
b.call(2, 4)
#=> 2
4
nil
//}
//emlist[lambda は引数の数が違うとエラーになる][ruby]{
b = lambda{|a,b,c|
p a,b,c
}
b.call(2, 4)
#=> wrong number of arguments (2 for 3) (ArgumentErr......_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)
//}
以下の表は、手続きオブジェクトの実行を上の例と同じように、手続きオブジェクトが定......数の数が違っていてもエラーにならない][ruby]{
b = Proc.new{|a,b,c|
p a,b,c
}
b.call(2, 4)
#=> 2
4
nil
//}
//emlist[lambda は引数の数が違うとエラーになる][ruby]{
b = lambda{|a,b,c|
p a,b,c
}
b.call(2, 4)
# => wrong number of arguments (given 2, expected 3)... -
手続きオブジェクトの挙動の詳細 (24.0)
-
手続きオブジェクトの挙動の詳細 * def * should_use_next * block * lambda_proc * orphan
...数の数が違っていてもエラーにならない][ruby]{
b = Proc.new{|a,b,c|
p a,b,c
}
b.call(2, 4)
#=> 2
4
nil
//}
//emlist[lambda は引数の数が違うとエラーになる][ruby]{
b = lambda{|a,b,c|
p a,b,c
}
b.call(2, 4)
#=> wrong number of arguments (2 for 3) (ArgumentErr......_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)
//}
以下の表は、手続きオブジェクトの実行を上の例と同じように、手続きオブジェクトが定......数の数が違っていてもエラーにならない][ruby]{
b = Proc.new{|a,b,c|
p a,b,c
}
b.call(2, 4)
#=> 2
4
nil
//}
//emlist[lambda は引数の数が違うとエラーになる][ruby]{
b = lambda{|a,b,c|
p a,b,c
}
b.call(2, 4)
# => wrong number of arguments (given 2, expected 3)...