@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; }
public final void fastASet(Ruby runtime, IRubyObject key, IRubyObject value, boolean prepareString) { if (prepareString) { fastASetCheckString(runtime, key, value); } else { fastASet(key, value); } }
@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, 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; }
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; }
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 RubyHash createHash(Ruby runtime, IRubyObject key1, IRubyObject value1, IRubyObject key2, IRubyObject value2) { RubyHash hash = createHash(runtime, key1, value1); hash.fastASet(key2, value2); return hash; } }
@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); } }
@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; }
@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; }
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; }
@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); } } }
@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); } } }
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 }
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 }
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 }
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 }
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 }
@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(); }