method_missing (like in ruby), catch all for methods

class Method_missing implements Dynamic
  {
    public static function
  main()
    {
    var t = new Method_missing();
    var r = t.some_unknown_method(11, "222s", 3.333);
    trace("-> " + r);
    var r = t.some_other_method("111s", 2.222, 33333);
    trace("-> " + r);
    }

    public function
  new()
    {}

    public static function
  show(x)
    {
    if(Reflect.isObject(x))
      return trace("  " + Type.getClassName(Type.getClass(x)) + "(" + x + ")");
    return trace("  " + Type.typeof(x) + "(" + x + ")");
    }

    function
  resolve( name : String ) : Array<Dynamic> -> Dynamic
    {
    trace(name);
    return
      Reflect.makeVarArgs(
        function(args : Array<Dynamic>) : Dynamic
          {
          var strs : Array<String> = [];
          var str = name + "(";
          for(x in args)
            {
            show(x);
            strs.push('${x}');
            }
          return name + "(" + strs.join(", ") + ")";
          }
        );
    }
  }

outputs

Method_missing.hx:29: some_unknown_method
Method_missing.hx:23:   TInt(11)
Method_missing.hx:22:   String(222s)
Method_missing.hx:23:   TFloat(3.333)
Method_missing.hx:9: -> some_unknown_method(11, 222s, 3.333)
Method_missing.hx:29: some_other_method
Method_missing.hx:22:   String(111s)
Method_missing.hx:23:   TFloat(2.222)
Method_missing.hx:23:   TInt(33333)
Method_missing.hx:11: -> some_other_method(111s, 2.222, 33333)
version #19856, modified 2013-12-17 19:51:25 by hg42