From: Robert Klemme Date: 2003-07-17T22:36:25+09:00 Subject: Re: callbacks in ruby and using yield in resursion "Paul" schrieb im Newsbeitrag news:1058402958.4573.7.camel@paulsmachine... > Hi, > > How do I pass a ruby function as an argument to another ruby function so > that it can be used as a callback? There is no such thing as a function, there are only methods in Ruby. You can create Method instances the way Brian showed in his posting. Another option is to use a block converted to a Proc: def fun2( fun, x ) fun.call( x, x ) end def add(x,y) x+y end # Method instance (C) 2003 Brian fun = method :add fun2( fun, 10 ) # Proc instance fun = proc {|x,y| x+y} fun2( fun, 10 ) You can even curry: def curry( fun, arg ) return proc {|x| fun.call(arg, x) } end fun = curry( method( :add ), 10 ) fun.call( 5 ) fun = curry( proc {|x,y| x+y}, 10 ) fun.call( 5 ) Regards robert