るりまサーチ

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

別のキーワード

  1. object tap
  2. _builtin tap
  3. tap object
  4. tap _builtin

クラス

モジュール

キーワード

検索結果

Object#tap {|x| ... } -> self (18127.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 (8.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...

Kernel.#lambda { ... } -> Proc (8.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...

Kernel.#proc -> Proc (8.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...

Kernel.#proc { ... } -> Proc (8.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...

絞り込み条件を変える

Object#then -> Enumerator (8.0)

self を引数としてブロックを評価し、ブロックの結果を返します。

...返します。
例えば条件によって値を捨てるのに使えます。

//emlist[][ruby]{
# 条件にあうので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}

@see Object#tap...

Object#then {|x| ... } -> object (8.0)

self を引数としてブロックを評価し、ブロックの結果を返します。

...返します。
例えば条件によって値を捨てるのに使えます。

//emlist[][ruby]{
# 条件にあうので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}

@see Object#tap...

Object#yield_self -> Enumerator (8.0)

self を引数としてブロックを評価し、ブロックの結果を返します。

...返します。
例えば条件によって値を捨てるのに使えます。

//emlist[][ruby]{
# 条件にあうので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}

@see Object#tap...

Object#yield_self {|x| ... } -> object (8.0)

self を引数としてブロックを評価し、ブロックの結果を返します。

...返します。
例えば条件によって値を捨てるのに使えます。

//emlist[][ruby]{
# 条件にあうので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}

@see Object#tap...

Proc (8.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...

絞り込み条件を変える