Symbols

Hi,

Is it possible to have and pass into a function a method which exists inside a module?

I have shared/reused function in a module, and would like to pass to a function. For example:
_timer = new Timer.Timer();
_timer.start(method(:MyModule.update), 1000, true);


When I've tried this, I get symbol not found on 'update'

Thanks
Chris
  • method() is resolving to a member function of the class you are calling from. You've essentially written self.method(:MyModule.update), which doesn't make any sense.

    If you want a Lang.Method for a function named update() in another object, call obj.method(:update). If you want to call a module function, use new Lang.Method(MyModule, :update).

    Travis
  • method() is resolving to a member function of the class you are calling from. You've essentially written self.method(:MyModule.update), which doesn't make any sense.

    If you want a Lang.Method for a function named update() in another object, call obj.method(:update). If you want to call a module function, use new Lang.Method(MyModule, :update).

    Travis


    Thanks Travis. I am now getting the error "UnexpectedTypeException: Expected Method, given Class definition" when using Lang.Method(MyModule, :update)

    Any ideas?
  • I'm guessing that you missed the new keyword in my quote. The following should work.

    var updateCallback = new Lang.Method(MyModule, :update);

    // just to prove you can invoke it
    updateCallback.invoke();


    Travis