String -> Symbol?

Former Member
Former Member

I'm trying to make a dynamic dispatch based on external data, and making "handler" functions on a specific key.

It appears that the method / method.invoke calls only accept symbols, which is fine -- how do I convert a string to a symbol?  Or if not that, make some form of dynamic runtime function exec?

Example of what I'm trying...1

function dispatcher( action ) {

    var methname = "handle_" + action;

    var sym = methname.toSymbol();   // <--- not a thing

    if ( self has sym ) {

        var meth = self.method( :sym );

        meth.invoke( ... );

     }

     else {

        System.println( "Ignoring action " + action + ", no handler for it." );

     }

}

Suggestions welcome.