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

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

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

RubyHash.newHash介绍

[英]rb_hash_new
[中]rb_hash_new

代码示例

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

@JRubyMethod(name = {"to_h", "to_hash"})
public RubyHash toHash(ThreadContext context) {
  return RubyHash.newHash(context.runtime, table, context.runtime.getNil());
}

代码示例来源: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: 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-core

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 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 IRubyObject hash(ThreadContext context, IRubyObject[] pairs) {
  Ruby runtime = context.runtime;
  RubyHash hash = RubyHash.newHash(runtime);
  for (int i = 0; i < pairs.length;) {
    hash.fastASetCheckString(runtime, pairs[i++], pairs[i++]);
  }
  return hash;
}

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

/** rb_hash_reject
 *
 */
public RubyHash rejectInternal(ThreadContext context, Block block) {
  final RubyHash result = newHash(context.runtime);
  iteratorVisitAll(context, new RejectVisitor(result), block);
  return result;
}

代码示例来源: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

/** rb_hash_invert
 *
 */
@JRubyMethod(name = "invert")
public RubyHash invert(final ThreadContext context) {
  final RubyHash result = newHash(getRuntime());
  visitAll(context, InvertVisitor, result);
  return result;
}

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

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: asciidoctor/asciidoctorj

private static void handleDefaultAttributeAnnotation(Class<? extends Processor> processor, RubyClass rubyClass) {
  Ruby rubyRuntime = rubyClass.getRuntime();
  if (processor.isAnnotationPresent(DefaultAttribute.class)) {
    DefaultAttribute defaultAttribute = processor.getAnnotation(DefaultAttribute.class);
    RubyHash defaultAttrs = RubyHash.newHash(rubyRuntime);
    defaultAttrs.put(defaultAttribute.key(), defaultAttribute.value());
    rubyClass.callMethod(rubyRuntime.getCurrentContext(), "option", new IRubyObject[]{
        rubyRuntime.newSymbol("default_attrs"),
        defaultAttrs
    });
  }
}

代码示例来源:origin: org.asciidoctor/asciidoctorj

private static void handleDefaultAttributeAnnotation(Class<? extends Processor> processor, RubyClass rubyClass) {
  Ruby rubyRuntime = rubyClass.getRuntime();
  if (processor.isAnnotationPresent(DefaultAttribute.class)) {
    DefaultAttribute defaultAttribute = processor.getAnnotation(DefaultAttribute.class);
    RubyHash defaultAttrs = RubyHash.newHash(rubyRuntime);
    defaultAttrs.put(defaultAttribute.key(), defaultAttribute.value());
    rubyClass.callMethod(rubyRuntime.getCurrentContext(), "option", new IRubyObject[]{
        rubyRuntime.newSymbol("default_attrs"),
        defaultAttrs
    });
  }
}

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

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

代码示例来源:origin: org.asciidoctor/asciidoctorj

@Override
public Column createTableColumn(Table parent, int index, Map<String, Object> attributes) {
  Ruby rubyRuntime = JRubyRuntimeContext.get(parent);
  RubyHash rubyAttributes = RubyHash.newHash(rubyRuntime);
  rubyAttributes.putAll(attributes);
  IRubyObject[] parameters = {
      ((StructuralNodeImpl) parent).getRubyObject(),
      RubyFixnum.newFixnum(rubyRuntime, index),
      rubyAttributes}; // No cursor parameter yet
  return (Column) NodeConverter.createASTNode(rubyRuntime, TABLE_COLUMN_CLASS, parameters);
}

代码示例来源:origin: asciidoctor/asciidoctorj

@Override
public Column createTableColumn(Table parent, int index, Map<String, Object> attributes) {
  Ruby rubyRuntime = JRubyRuntimeContext.get(parent);
  RubyHash rubyAttributes = RubyHash.newHash(rubyRuntime);
  rubyAttributes.putAll(attributes);
  IRubyObject[] parameters = {
      ((StructuralNodeImpl) parent).getRubyObject(),
      RubyFixnum.newFixnum(rubyRuntime, index),
      rubyAttributes}; // No cursor parameter yet
  return (Column) NodeConverter.createASTNode(rubyRuntime, TABLE_COLUMN_CLASS, parameters);
}

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

/** rb_hash_select
 *
 */
@JRubyMethod(name = "select")
public IRubyObject select(final ThreadContext context, final Block block) {
  final Ruby runtime = context.runtime;
  if (!block.isGiven()) return enumeratorizeWithSize(context, this, "select", enumSizeFn());
  final RubyHash result = newHash(runtime);
  iteratorVisitAll(context, new SelectVisitor(result), block);
  return result;
}

代码示例来源:origin: asciidoctor/asciidoctorj

public static NodeCache get(IRubyObject rubyObject) {
  RubyHash cache = (RubyHash) rubyObject.getInstanceVariables().getInstanceVariable(ASCIIDOCTORJ_CACHE);
  if (cache == null) {
    cache = RubyHash.newHash(rubyObject.getRuntime());
    rubyObject.getInstanceVariables().setInstanceVariable(ASCIIDOCTORJ_CACHE, cache);
  }
  return new NodeCache(cache);
}

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

@JRubyMethod(name = "to_h", rest = true)
public static IRubyObject to_h(ThreadContext context, IRubyObject self, IRubyObject[] args) {
  final Ruby runtime = context.runtime;
  final RubyHash result = RubyHash.newHash(runtime);
  Helpers.invoke(context, self, "each", args, CallBlock.newCallClosure(self, runtime.getEnumerable(),
      Signature.OPTIONAL, new PutKeyValueCallback(result), context));
  result.infectBy(self);
  return result;
}

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

public static RubyHash unmarshalFrom(UnmarshalStream input, boolean defaultValue) throws IOException {
  RubyHash result = newHash(input.getRuntime());
  input.registerLinkTarget(result);
  int size = input.unmarshalInt();
  for (int i = 0; i < size; i++) {
    result.fastASetCheckString(input.getRuntime(), input.unmarshalObject(), input.unmarshalObject());
  }
  if (defaultValue) result.default_value_set(input.unmarshalObject());
  return result;
}

相关文章

微信公众号

最新文章

更多

RubyHash类方法