LoginSignup
1
0

More than 5 years have passed since last update.

【Ruby】ブロックの小さなサンプル

Posted at

参考
https://qiita.com/kidach1/items/15cfee9ec66804c3afd2

# &でブロックを引数に
def exec_block(&block)
  block.call
end

exec_block do
  p "p_bloack"
end


####Proc
proc = Proc.new do
  p "proc_new"
end

proc.call

#### yield
def exec_block2(&block)
  yield
end

exec_block2 do
  p "block2"
end
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0