@RubyLevelMethod(name = "eval", module = true)
 public static RubyValue eval(RubyValue receiver, RubyValue arg0, RubyValue arg1) {
   if (arg1 instanceof RubyBinding) {
     return eval(arg0.toStr(), (RubyBinding) arg1);
   } else {
     return eval(arg0.toStr());
   }
 }
  @RubyLevelMethod(name = "__load_with_reflection__", module = true)
  public static RubyValue loadWithReflection(RubyValue receiver, RubyValue arg, RubyBlock block) {
    String required_file = arg.toStr();
    String name = NameFactory.createMainClassName(required_file);
    try {
      Class c = Class.forName(name);
      Object o = c.newInstance();
      RubyProgram p = (RubyProgram) o;

      // $".push(file_name) unless $".include?(file_name)
      RubyArray a = (RubyArray) GlobalVariables.get("$\"");
      if (a.include(arg) == RubyConstant.QFALSE) {
        a.push(arg);
      }

      p.invoke();
      return RubyConstant.QTRUE;
    } catch (ClassNotFoundException e) {
      return RubyConstant.QFALSE;
    } catch (InstantiationException e) {
      return RubyConstant.QFALSE;
    } catch (IllegalAccessException e) {
      return RubyConstant.QFALSE;
    }
  }
 @RubyLevelMethod(name = "method")
 public static RubyValue objMethod(RubyValue receiver, RubyValue arg) {
   String method_name = arg.toStr();
   RubyID mid = RubyID.intern(method_name);
   RubyMethod m = receiver.findMethod(mid);
   if (null == m) {
     throw new RubyException(
         RubyRuntime.NameErrorClass,
         "public method '"
             + method_name
             + "' can not be found in '"
             + receiver.getRubyClass().getName()
             + "'");
   }
   return ObjectFactory.createMethod(receiver, method_name, m);
 }
  @RubyLevelMethod(name = "require_java", alias = "import", module = true)
  public static RubyValue requireJava(RubyValue receiver, RubyValue arg, RubyBlock block) {
    String className = arg.toStr();
    String[] names = packagePattern.split(className);
    String name = names[names.length - 1];
    if (name.equals("*")) {
      JavaClass.addPackage(className.substring(0, className.lastIndexOf('.')));
    } else {
      try {
        Class clazz = Class.forName(className);
        JavaClass.createJavaClass(clazz);
      } catch (ClassNotFoundException e) {
        throw new RubyException("Couldn't find class " + className);
      }
    }

    RubyRuntime.setJavaSupported(true);
    return RubyConstant.QTRUE;
  }
 @RubyLevelMethod(name = "eval", module = true)
 public static RubyValue eval(RubyValue receiver, RubyValue arg) {
   return eval(arg.toStr());
 }
 @RubyLevelMethod(name = "send", alias = "__send__")
 public static RubyValue send(RubyValue receiver, RubyArray args, RubyBlock block) {
   RubyValue method_name = args.delete_at(0);
   RubyID mid = RubyID.intern(method_name.toStr());
   return RubyAPI.callMethod(receiver, args, block, mid);
 }
 @RubyLevelMethod(name = "send", alias = "__send__")
 public static RubyValue send(
     RubyValue receiver, RubyValue arg0, RubyValue arg1, RubyBlock block) {
   RubyID mid = RubyID.intern(arg0.toStr());
   return RubyAPI.callOneArgMethod(receiver, arg1, block, mid);
 }
Пример #8
0
 // @RubyLevelMethod(name="initialize", alias="initialize_copy")
 public RubyString initialize(RubyValue v) {
   this.setString(v.toStr());
   return this;
 }
Пример #9
0
 // RHO_MOBILE
 // @RubyLevelMethod(name = "include?")
 public RubyValue include_p(RubyValue arg) {
   int nIndex = sb_.toString().indexOf(arg.toStr());
   return ObjectFactory.createBoolean(nIndex >= 0);
 }