From: "Jesús Gabriel y Galán" Date: 2009-12-30T20:51:54+09:00 Subject: Re: How to pass a function as parameter? 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 Or if in the executer you want to store the block for later use: def executer(&block) @save_for_later = block end #later... @save_for_later.call(1) #or @save_for_later[1] Hope this helps, Jesus.