Example #1
0
  public static void initARGV(Ruby runtime) {
    // define ARGV and $* for this runtime
    RubyArray argvArray = runtime.newArray();
    String[] argv = runtime.getInstanceConfig().getArgv();

    for (String arg : argv) {
      argvArray.append(RubyString.newInternalFromJavaExternal(runtime, arg));
    }

    if (runtime.getObject().getConstantNoConstMissing("ARGV") != null) {
      ((RubyArray) runtime.getObject().getConstant("ARGV")).replace(argvArray);
    } else {
      runtime.getObject().setConstantQuiet("ARGV", argvArray);
      runtime.getGlobalVariables().define("$*", new ValueAccessor(argvArray), GLOBAL);
    }
  }
Example #2
0
 private RubyString getCorrectKey(IRubyObject key, ThreadContext context) {
   RubyString originalKey = key.convertToString();
   RubyString actualKey = originalKey;
   Ruby runtime = context.runtime;
   if (Platform.IS_WINDOWS) {
     // this is a rather ugly hack, but similar to MRI. See hash.c:ruby_setenv and similar in MRI
     // we search all keys for a case-insensitive match, and use that
     RubyArray keys = super.keys();
     for (int i = 0; i < keys.size(); i++) {
       RubyString candidateKey = keys.eltInternal(i).convertToString();
       if (candidateKey
           .casecmp(context, originalKey)
           .op_equal(context, RubyFixnum.zero(runtime))
           .isTrue()) {
         actualKey = candidateKey;
         break;
       }
     }
   }
   return actualKey;
 }