MethodMissingMethod.java

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */

  5. package org.jruby.internal.runtime.methods;

  6. import org.jruby.RubyModule;
  7. import org.jruby.RubyString;
  8. import org.jruby.runtime.Block;
  9. import org.jruby.runtime.ThreadContext;
  10. import org.jruby.runtime.builtin.IRubyObject;

  11. /**
  12.  *
  13.  * @author enebo
  14.  */
  15. public class MethodMissingMethod extends DynamicMethod {
  16.     private RubyString name;

  17.     public MethodMissingMethod(RubyModule implementationClass, RubyString name) {
  18.         super(implementationClass, null, null);

  19.         this.name = name;
  20.     }

  21.     /**
  22.      * @see org.jruby.runtime.ICallable#call(Ruby, IRubyObject, String, IRubyObject[], boolean)
  23.      */
  24.     public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject[] args, Block block) {
  25.         args = createArgs(args);

  26.         // TODO: Callsite cache of method_missing
  27.         return self.callMethod(context, "method_missing", args, block);
  28.     }

  29.     private IRubyObject[] createArgs(IRubyObject[] args) {
  30.         IRubyObject[] newArgs = new IRubyObject[args.length + 1];

  31.         System.arraycopy(args, 0, newArgs, 1, args.length);
  32.         newArgs[0] = name;

  33.         return newArgs;
  34.     }

  35.     public DynamicMethod dup() {
  36.         return new MethodMissingMethod(getImplementationClass(), name);
  37.     }
  38. }