From: Luca Pireddu Date: 2005-04-23T08:39:32+09:00 Subject: Re: Nuby Question - How do you assign a function itself? Austin Ziegler wrote: > On 4/22/05, Sam Kong wrote: >> What I want is to assign the function to g so that I can call g instead >> of f. >> >> All I could find was >> alias :g :f > > You can't. > > You can, however do: > > g = method(:f) > > You can't just do g, though, because g is now a method object. You > need to do either g.call or g[]. > > -austin Another alternative may to to use Proc objects f = Proc.new { |x| x*x } g = f g.call(2) Or maybe a functor-style construct class Raise def initialize(exponent) @exponent = exponent end def call(x) � return x ** @exponent end end f = Raise.new(3) g = f g.call(2) Hope that helps Luca