るりまサーチ

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

別のキーワード

  1. _builtin each_object
  2. objectspace each_object
  3. object send
  4. object to_enum
  5. pp object_group

ライブラリ

クラス

モジュール

キーワード

検索結果

Object#tap {|x| ... } -> self (62131.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 (21120.0)

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

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

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

@see Object#tap...

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

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

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

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

@see Object#tap...

Object#then -> Enumerator (21020.0)

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

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

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

@see Object#tap...

Object#yield_self -> Enumerator (21020.0)

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

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

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

@see Object#tap...

絞り込み条件を変える

VALUE rb_data_object_alloc(VALUE klass, void *datap, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree) (6200.0)

datap をラップするオブジェクトを生成し、返します。 そのクラスは klass となり、datap をマークするときは dmark、解放するときは dfree を使うようになります。

...datap をラップするオブジェクトを生成し、返します。
そのクラスは klass となり、datap をマークするときは
dmark、解放するときは dfree を使うようになります。...

Kernel.#lambda -> Proc (24.0)

与えられたブロックから手続きオブジェクト (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 では...
...pturing 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 スタック上にブロックがないのにブロックを省略した呼び出し...
..._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 (24.0)

与えられたブロックから手続きオブジェクト (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 では...
...pturing 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 スタック上にブロックがないのにブロックを省略した呼び出し...
..._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 (24.0)

与えられたブロックから手続きオブジェクト (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 では...
...pturing 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 スタック上にブロックがないのにブロックを省略した呼び出し...
..._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 (24.0)

与えられたブロックから手続きオブジェクト (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 では...
...pturing 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 スタック上にブロックがないのにブロックを省略した呼び出し...
..._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...

絞り込み条件を変える