@JRubyMethod(name = {"to_h", "to_hash"}) public RubyHash toHash(ThreadContext context) { return RubyHash.newHash(context.runtime, table, context.runtime.getNil()); }
@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; }
@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; }
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; }
public static RubyHash createHash(Ruby runtime, IRubyObject key, IRubyObject value) { RubyHash hash = RubyHash.newHash(runtime); hash.fastASet(key, value); return hash; }
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; }
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; }
/** rb_hash_reject * */ public RubyHash rejectInternal(ThreadContext context, Block block) { final RubyHash result = newHash(context.runtime); iteratorVisitAll(context, new RejectVisitor(result), block); return result; }
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; }
/** rb_hash_invert * */ @JRubyMethod(name = "invert") public RubyHash invert(final ThreadContext context) { final RubyHash result = newHash(getRuntime()); visitAll(context, InvertVisitor, result); return result; }
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; }
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 }); } }
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 }); } }
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; }
@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); }
@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); }
/** 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; }
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); }
@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; }
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; }