From: Jeff Peng Date: 2009-12-30T21:00:35+09:00 Subject: Re: How to pass a function as parameter? Jes�s Gabriel y Gal�n: > On Wed, Dec 30, 2009 at 12:42 PM, Fritz Trapper wrote: >> I want to pass a reference to function as parameter to another function >> and execute the passed function. Somthing like this: >> >> def executer(func) >> func(1) >> end >> >> def test(x) >> p x >> end >> >> executer(test) >> >> How to write this correctly in ruby? > > A typical way would be using blocks or procs: > > def executer > yield 1 > end > > executer {|x| puts "I got #{x}"} > > If you want something to handle around in a variable: > > func = lambda {|x| puts "I got #{x}"} > executer(&func) # => I got 1 > for &func, what's the "&" before "func" here? Thanks.