throw runtime.newArgumentError("expected Hash arguments."); RubyHash hash = args[0].convertToHash(); hash.visitAll(new RubyHash.Visitor() { @Override
@JRubyMethod(name = ">=", required = 1) public IRubyObject op_ge(ThreadContext context, IRubyObject other) { final RubyHash otherHash = other.convertToHash(); return otherHash.op_le(context, this); }
@JRubyMethod(name = ">=", required = 1) public IRubyObject op_ge(ThreadContext context, IRubyObject other) { final RubyHash otherHash = other.convertToHash(); return otherHash.op_le(context, this); }
@JRubyMethod(name = ">", required = 1) public IRubyObject op_gt(ThreadContext context, IRubyObject other) { final RubyHash otherHash = other.convertToHash(); return otherHash.op_lt(context, this); }
@JRubyMethod(name = ">", required = 1) public IRubyObject op_gt(ThreadContext context, IRubyObject other) { final RubyHash otherHash = other.convertToHash(); return otherHash.op_lt(context, this); }
@JRubyMethod(name = "<=", required = 1) public IRubyObject op_le(ThreadContext context, IRubyObject other) { final RubyHash otherHash = other.convertToHash(); if (size() > otherHash.size()) return context.fals; return RubyBoolean.newBoolean(context.runtime, hash_le(otherHash)); }
@JRubyMethod(name = "<=", required = 1) public IRubyObject op_le(ThreadContext context, IRubyObject other) { final RubyHash otherHash = other.convertToHash(); if (size() > otherHash.size()) return context.fals; return RubyBoolean.newBoolean(context.runtime, hash_le(otherHash)); }
public static CodingActions processCodingErrorActions(ThreadContext context, IRubyObject opts) { if (opts == null || opts.isNil()) { return new CodingActions(CodingErrorAction.REPORT, CodingErrorAction.REPORT, 0, null); } Ruby runtime = context.runtime; int flags = 0; RubyHash hash = opts.convertToHash(); flags |= EncodingUtils.econvPrepareOpts(context, opts, new IRubyObject[]{opts}); IRubyObject replace = hash.fastARef(runtime.newSymbol("replace")); return processCodingErrorActions(context, flags, replace); }
/** rb_hash_update * */ @JRubyMethod(name = {"merge!", "update"}, required = 1) public RubyHash merge_bang(ThreadContext context, IRubyObject other, Block block) { modify(); final RubyHash otherHash = other.convertToHash(); if (otherHash.empty_p().isTrue()) return this; otherHash.visitAll(context, new MergeVisitor(this), block); return this; }
/** rb_hash_update * */ @JRubyMethod(name = {"merge!", "update"}, required = 1) public RubyHash merge_bang(ThreadContext context, IRubyObject other, Block block) { modify(); final RubyHash otherHash = other.convertToHash(); if (otherHash.empty_p().isTrue()) return this; otherHash.visitAll(context, new MergeVisitor(this), block); return this; }
public static CodingActions processCodingErrorActions(ThreadContext context, IRubyObject opts) { if (opts == null || opts.isNil()) { return new CodingActions(CodingErrorAction.REPORT, CodingErrorAction.REPORT, 0, null); } Ruby runtime = context.runtime; int flags = 0; RubyHash hash = opts.convertToHash(); flags |= EncodingUtils.econvPrepareOpts(context, opts, new IRubyObject[]{opts}); IRubyObject replace = hash.fastARef(runtime.newSymbol("replace")); return processCodingErrorActions(context, flags, replace); }
@JRubyMethod(name = "system", required = 1, rest = true, module = true, visibility = PRIVATE, compat = CompatVersion.RUBY1_9) public static IRubyObject system19(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; if (args[0] instanceof RubyHash) { RubyHash env = (RubyHash) args[0].convertToHash(); if (env != null) { runtime.getENV().merge_bang(context, env, Block.NULL_BLOCK); } // drop the first element for calling systemCommon() IRubyObject[] rest = new IRubyObject[args.length - 1]; System.arraycopy(args, 1, rest, 0, args.length - 1); args = rest; } int resultCode = systemCommon(context, recv, args); switch (resultCode) { case 0: return runtime.getTrue(); case 127: return runtime.getNil(); default: return runtime.getFalse(); } }
private RubyHash replaceCommon(final ThreadContext context, IRubyObject other, Visitor visitor) { modify(); final RubyHash otherHash = other.convertToHash(); if (this == otherHash) return this; rb_clear(); if (!isComparedByIdentity() && otherHash.isComparedByIdentity()) { setComparedByIdentity(true); } otherHash.visitAll(visitor); ifNone = otherHash.ifNone; if ((otherHash.flags & PROCDEFAULT_HASH_F) != 0) { flags |= PROCDEFAULT_HASH_F; } else { flags &= ~PROCDEFAULT_HASH_F; } return this; }
private RubyHash replaceCommon19(final ThreadContext context, IRubyObject other, Visitor visitor) { modify(); final RubyHash otherHash = other.convertToHash(); if (this == otherHash) return this; rb_clear(); if (!isComparedByIdentity() && otherHash.isComparedByIdentity()) { setComparedByIdentity(true); } otherHash.visitAll(visitor); ifNone = otherHash.ifNone; if ((otherHash.flags & PROCDEFAULT_HASH_F) != 0) { flags |= PROCDEFAULT_HASH_F; } else { flags &= ~PROCDEFAULT_HASH_F; } return this; }
private RubyHash replaceCommon(final ThreadContext context, IRubyObject other, Visitor visitor) { modify(); final RubyHash otherHash = other.convertToHash(); if (this == otherHash) return this; rb_clear(); if (!isComparedByIdentity() && otherHash.isComparedByIdentity()) { setComparedByIdentity(true); } otherHash.visitAll(visitor); ifNone = otherHash.ifNone; if ((otherHash.flags & PROCDEFAULT_HASH_F) != 0) { flags |= PROCDEFAULT_HASH_F; } else { flags &= ~PROCDEFAULT_HASH_F; } return this; }
private RubyHash replaceCommon19(final ThreadContext context, IRubyObject other, Visitor visitor) { modify(); final RubyHash otherHash = other.convertToHash(); if (this == otherHash) return this; rb_clear(); if (!isComparedByIdentity() && otherHash.isComparedByIdentity()) { setComparedByIdentity(true); } otherHash.visitAll(visitor); ifNone = otherHash.ifNone; if ((otherHash.flags & PROCDEFAULT_HASH_F) != 0) { flags |= PROCDEFAULT_HASH_F; } else { flags &= ~PROCDEFAULT_HASH_F; } return this; }
@JIT @Interp public static IRubyObject mergeKeywordArguments(ThreadContext context, IRubyObject restKwarg, IRubyObject explicitKwarg) { RubyHash hash = (RubyHash) TypeConverter.checkHashType(context.runtime, restKwarg).dup(); hash.modify(); final RubyHash otherHash = explicitKwarg.convertToHash(); if (otherHash.empty_p().isTrue()) return hash; otherHash.visitAll(context, new KwargMergeVisitor(hash), Block.NULL_BLOCK); return hash; }
@JIT @Interp public static IRubyObject mergeKeywordArguments(ThreadContext context, IRubyObject restKwarg, IRubyObject explicitKwarg) { RubyHash hash = (RubyHash) TypeConverter.checkHashType(context.runtime, restKwarg).dup(); hash.modify(); final RubyHash otherHash = explicitKwarg.convertToHash(); if (otherHash.empty_p().isTrue()) return hash; otherHash.visitAll(context, new KwargMergeVisitor(hash), Block.NULL_BLOCK); return hash; }
/** rb_hash_replace * */ @JRubyMethod(name = "replace", required = 1) public RubyHash replace(final ThreadContext context, IRubyObject other) { modify(); final RubyHash otherHash = other.convertToHash(); if (this == otherHash) return this; rb_clear(); if (!isComparedByIdentity() && otherHash.isComparedByIdentity()) { setComparedByIdentity(true); } otherHash.visitAll(context, ReplaceVisitor, this); ifNone = otherHash.ifNone; if ((otherHash.flags & PROCDEFAULT_HASH_F) != 0) { flags |= PROCDEFAULT_HASH_F; } else { flags &= ~PROCDEFAULT_HASH_F; } return this; }
@JRubyMethod(optional = 1) public static IRubyObject initialize(IRubyObject self, IRubyObject[] args) { IRubyObject options = null; if(args.length == 0) { options = RubyHash.newHash(self.getRuntime()); } else { options = args[0].convertToHash(); } ((RubyObject)self).fastSetInstanceVariable("@options", options); ((RubyObject)self).fastSetInstanceVariable("@input", self.getRuntime().getNil()); ((RubyObject)self).fastSetInstanceVariable("@resolver", self.getRuntime().getNil()); return self; }