u16suzuの blog

日々学んだことのメモブログです。

2012-01-30から1日間の記事一覧

Procオブジェクト生成方法の3種盛り合わせ

メタプロより。 inc = Proc.new { |x| x+1} p inc.class p inc.call(33) dec = lambda { |x| x-1} p dec.class p dec.call(33) def fuga(&the_proc) the_proc end mul = fuga{|x, y| x*y} p mul.class p mul.call(4,5) 結果 Proc 34 Proc 32 Proc 203番目の…

yieldメモ

&を使うことでメソッドにブロックを渡すことができる。 def hoge(a, b, &op) yield a, b end p hoge(3,4){|x,y| x*y}