From: Brian Candler Date: 2009-01-29T04:01:49+09:00 Subject: Re: function inside a function Ruben Medellin wrote: > In ruby, function_a is a method call (with no arguments), and as a > call, it gets evaluated to whatever that function returns. If you > wanted to grab the function as a "pure function", you'd use lambdas or > Procs like Jes�s pointed. > > In other words: > > function_a = Proc.new {|x| ..do something with x... } > > returns a functional object. You can then call the method with > function_a.call (aliased []) Or, if you really want to do this with def'd methods, you can use obj.method(:function_a) which will turn an existing method (bound to the instance 'obj') into a Proc-like thing that you can pass around and call later. def function_a(x = 1) x**2 + x end def function_b(any_function) y = 4 + 5 any_function.call(y) # or: any_function[y] end puts function_b(method(:function_a)) -- Posted via http://www.ruby-forum.com/.