org.jruby.RubyHash.fastASet()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(146)

本文整理了Java中org.jruby.RubyHash.fastASet方法的一些代码示例,展示了RubyHash.fastASet的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RubyHash.fastASet方法的具体详情如下:
包路径:org.jruby.RubyHash
类名称:RubyHash
方法名:fastASet

RubyHash.fastASet介绍

暂无

代码示例

代码示例来源:origin: bazelbuild/bazel

@JRubyMethod(name = "decode_json", meta = true)
public static IRubyObject decodeJson(ThreadContext context, IRubyObject recv, IRubyObject json) {
  Ruby runtime = context.runtime;
  RubyMessage ret = (RubyMessage) ((RubyClass) recv).newInstance(context, Block.NULL_BLOCK);
  RubyModule jsonModule = runtime.getClassFromPath("JSON");
  RubyHash opts = RubyHash.newHash(runtime);
  opts.fastASet(runtime.newSymbol("symbolize_names"), runtime.getTrue());
  IRubyObject[] args = new IRubyObject[] { Helpers.invoke(context, jsonModule, "parse", json, opts) };
  ret.initialize(context, args);
  return ret;
}

代码示例来源:origin: org.jruby/jruby-complete

public final void fastASet(Ruby runtime, IRubyObject key, IRubyObject value, boolean prepareString) {
  if (prepareString) {
    fastASetCheckString(runtime, key, value);
  } else {
    fastASet(key, value);
  }
}

代码示例来源:origin: bazelbuild/bazel

@JRubyMethod(name = {"to_h", "to_hash"})
public IRubyObject toHash(ThreadContext context) {
  Ruby runtime = context.runtime;
  RubyHash ret = RubyHash.newHash(runtime);
  for (Descriptors.FieldDescriptor fdef : this.descriptor.getFields()) {
    IRubyObject value = getField(context, fdef);
    if (!value.isNil()) {
      if (fdef.isRepeated() && !fdef.isMapField()) {
        if (fdef.getType() != Descriptors.FieldDescriptor.Type.MESSAGE) {
          value = Helpers.invoke(context, value, "to_a");
        } else {
          RubyArray ary = value.convertToArray();
          for (int i = 0; i < ary.size(); i++) {
            IRubyObject submsg = Helpers.invoke(context, ary.eltInternal(i), "to_h");
            ary.eltInternalSet(i, submsg);
          }
          value = ary.to_ary();
        }
      } else if (value.respondsTo("to_h")) {
        value = Helpers.invoke(context, value, "to_h");
      } else if (value.respondsTo("to_a")) {
        value = Helpers.invoke(context, value, "to_a");
      }
    }
    ret.fastASet(runtime.newSymbol(fdef.getName()), value);
  }
  return ret;
}

代码示例来源:origin: org.jruby/jruby-complete

public static RubyHash constructHash(Ruby runtime,
                   IRubyObject key1, IRubyObject value1, boolean prepareString1,
                   IRubyObject key2, IRubyObject value2, boolean prepareString2,
                   IRubyObject key3, IRubyObject value3, boolean prepareString3) {
  RubyHash hash = RubyHash.newHash(runtime);
  hash.fastASet(runtime, key1, value1, prepareString1);
  hash.fastASet(runtime, key2, value2, prepareString2);
  hash.fastASet(runtime, key3, value3, prepareString3);
  return hash;
}

代码示例来源:origin: org.jruby/jruby-complete

public static RubyHash constructHash(Ruby runtime,
                   IRubyObject key1, IRubyObject value1, boolean prepareString1,
                   IRubyObject key2, IRubyObject value2, boolean prepareString2) {
  RubyHash hash = RubyHash.newHash(runtime);
  hash.fastASet(runtime, key1, value1, prepareString1);
  hash.fastASet(runtime, key2, value2, prepareString2);
  return hash;
}

代码示例来源:origin: org.jruby/jruby-complete

public static RubyHash createHash(Ruby runtime, IRubyObject key, IRubyObject value) {
  RubyHash hash = RubyHash.newHash(runtime);
  hash.fastASet(key, value);
  return hash;
}

代码示例来源:origin: org.jruby/jruby-complete

public static RubyHash constructHash(Ruby runtime,
                   IRubyObject key1, IRubyObject value1, boolean prepareString1) {
  RubyHash hash = RubyHash.newHash(runtime);
  hash.fastASet(runtime, key1, value1, prepareString1);
  return hash;
}

代码示例来源:origin: org.jruby/jruby-complete

public static RubyHash createHash(Ruby runtime, IRubyObject key1, IRubyObject value1,
                   IRubyObject key2, IRubyObject value2) {
    RubyHash hash = createHash(runtime, key1, value1);

    hash.fastASet(key2, value2);

    return hash;
  }
}

代码示例来源:origin: org.jruby/jruby-complete

@Override
  public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyObject value, int index, RubyHash result) {
    IRubyObject newKey = block.yield(context, key);
    result.fastASet(newKey, value);
  }
}

代码示例来源:origin: org.jruby/jruby-complete

@JIT
public static RubyHash dupKwargsHashAndPopulateFromArray(ThreadContext context, RubyHash dupHash, IRubyObject[] pairs) {
  Ruby runtime = context.runtime;
  RubyHash hash = dupHash.dupFast(context);
  for (int i = 0; i < pairs.length;) {
    hash.fastASet(runtime, pairs[i++], pairs[i++], true);
  }
  return hash;
}

代码示例来源:origin: org.jruby/jruby-core

@JIT
public static RubyHash dupKwargsHashAndPopulateFromArray(ThreadContext context, RubyHash dupHash, IRubyObject[] pairs) {
  Ruby runtime = context.runtime;
  RubyHash hash = dupHash.dupFast(context);
  for (int i = 0; i < pairs.length;) {
    hash.fastASet(runtime, pairs[i++], pairs[i++], true);
  }
  return hash;
}

代码示例来源:origin: org.jruby/jruby-complete

private RubyHash makeHash(ThreadContext context, RubyHash hash, Block block) {
  for (int i = 0; i < realLength; i++) {
    IRubyObject v = elt(i);
    IRubyObject k = block.yield(context, v);
    if (hash.fastARef(k) == null) hash.fastASet(k, v);
  }
  return hash;
}

代码示例来源:origin: org.jruby/jruby-core

@Override
  public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyObject value, int index, Block block) {
    if (!block.yieldArray(context, RubyArray.newArray(context.runtime, key, value), null).isTrue()) {
      result.fastASet(key, value);
    }
  }
}

代码示例来源:origin: org.jruby/jruby-complete

@Override
  public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyObject value, int index, Block block) {
    if (block.yieldArray(context, context.runtime.newArray(key, value), null).isTrue()) {
      result.fastASet(key, value);
    }
  }
}

代码示例来源:origin: org.jruby/jruby-complete

static IRubyObject _parse_mday(ThreadContext context, IRubyObject self, RubyString str, RubyHash hash) {
  final Ruby runtime = context.runtime;
  RubyRegexp re = newRegexpFromCache(runtime, _parse_mday, RE_OPTION_IGNORECASE);
  IRubyObject sub = subSpace(context, (RubyString) str, re);
  if (sub != context.nil) {
    hash.fastASet(runtime.newSymbol("mday"), ((RubyString) ((RubyMatchData) sub).at(1)).to_i());
    return context.tru;
  }
  return sub; // nil
}

代码示例来源:origin: org.jruby/jruby-core

static IRubyObject _parse_mday(ThreadContext context, IRubyObject self, RubyString str, RubyHash hash) {
  final Ruby runtime = context.runtime;
  RubyRegexp re = newRegexpFromCache(runtime, _parse_mday, RE_OPTION_IGNORECASE);
  IRubyObject sub = subSpace(context, (RubyString) str, re);
  if (sub != context.nil) {
    hash.fastASet(runtime.newSymbol("mday"), ((RubyString) ((RubyMatchData) sub).at(1)).to_i());
    return context.tru;
  }
  return sub; // nil
}

代码示例来源:origin: org.jruby/jruby-complete

static IRubyObject _parse_year(ThreadContext context, IRubyObject self, RubyString str, RubyHash hash) {
  final Ruby runtime = context.runtime;
  RubyRegexp re = RubyRegexp.newRegexp(runtime, _parse_year);
  IRubyObject sub = subSpace(context, (RubyString) str, re);
  if (sub != context.nil) {
    hash.fastASet(runtime.newSymbol("year"), ((RubyString) ((RubyMatchData) sub).at(1)).to_i());
    return context.tru;
  }
  return sub; // nil
}

代码示例来源:origin: org.jruby/jruby-complete

static IRubyObject _parse_day(ThreadContext context, IRubyObject self, RubyString str, RubyHash hash) {
  final Ruby runtime = context.runtime;
  RubyRegexp re = newRegexpFromCache(runtime, _parse_day, RE_OPTION_IGNORECASE);
  IRubyObject sub = subSpace(context, (RubyString) str, re);
  if (sub != context.nil) {
    int day = day_num((RubyString) ((RubyMatchData) sub).at(1));
    hash.fastASet(runtime.newSymbol("wday"), RubyFixnum.newFixnum(runtime, day));
    return context.tru;
  }
  return sub; // nil
}

代码示例来源:origin: org.jruby/jruby-complete

static IRubyObject _parse_mon(ThreadContext context, IRubyObject self, RubyString str, RubyHash hash) {
  final Ruby runtime = context.runtime;
  RubyRegexp re = newRegexpFromCache(runtime, _parse_mon, RE_OPTION_IGNORECASE);
  IRubyObject sub = subSpace(context, (RubyString) str, re);
  if (sub != context.nil) {
    int mon = mon_num((RubyString) ((RubyMatchData) sub).at(1));
    hash.fastASet(runtime.newSymbol("mon"), RubyFixnum.newFixnum(runtime, mon));
    return context.tru;
  }
  return sub; // nil
}

代码示例来源:origin: org.jruby/yecht

@JRubyMethod
public static IRubyObject add_type(IRubyObject self, IRubyObject taguri, IRubyObject cls) {
  IRubyObject tags = self.callMethod(self.getRuntime().getCurrentContext(), "tags");
  ((RubyHash)tags).fastASet(taguri, cls);
  return self.getRuntime().getNil();
}

相关文章

微信公众号

最新文章

更多

RubyHash类方法