LoginSignup
0
0

More than 5 years have passed since last update.

rubyのProc.newの実験

Last updated at Posted at 2013-04-24

Proc.newを実験してみました。
blockに名前を付けて使いまわす時に使えそう。

def test_proc1(v, proc)
  proc.call(v)
end

def test_proc2(v, proc)
  "#{proc.call(v)}%"
end

pr = Proc.new do |v|
  v*100
end

val = test_proc1(1, pr)
puts val #=> 100

percent = test_proc2(2, pr)
puts percent #=> 200%
0
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
0
0