Guest User

Untitled

a guest
Oct 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. # ブロックをProcオブジェクトにする
  2. sample_proc_1 = proc { |n| n * n }
  3. sample_proc_2 = Proc.new { |n| n ** 3 }
  4.  
  5. # Procオブジェクトを呼び出し実行
  6. sample_proc_1.call(2) #=> 4
  7. sample_proc_2.call(2) #=> 8
  8.  
  9. # メソッドから呼び出す時
  10. def sample(&sample_proc_3)
  11. puts sample_proc_3.call(2)
  12. end
  13.  
  14. sample { |n| n ** 4 } #=> 16
Add Comment
Please, Sign In to add comment