@Override public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyObject value, int index, Block block) { // All kwargs keys must be symbols. TypeConverter.checkType(context, key, context.runtime.getSymbol()); target.op_aset(context, key, value); } }
@Override public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyObject value, int index, Block block) { // All kwargs keys must be symbols. TypeConverter.checkType(context, key, context.runtime.getSymbol()); target.op_aset(context, key, value); } }
private static IRubyObject toHash(ThreadContext context, IRubyObject lastArg) { if (lastArg instanceof RubyHash) return (RubyHash) lastArg; if (lastArg.respondsTo("to_hash")) { lastArg = lastArg.callMethod(context, "to_hash"); if (lastArg == context.nil) return lastArg; TypeConverter.checkType(context, lastArg, context.runtime.getHash()); return (RubyHash) lastArg; } return null; }
private static IRubyObject toHash(ThreadContext context, IRubyObject lastArg) { if (lastArg instanceof RubyHash) return (RubyHash) lastArg; if (lastArg.respondsTo("to_hash")) { lastArg = lastArg.callMethod(context, "to_hash"); if (lastArg == context.nil) return lastArg; TypeConverter.checkType(context, lastArg, context.runtime.getHash()); return (RubyHash) lastArg; } return null; }
public static Boolean doReverseLookup(ThreadContext context, IRubyObject noreverse) { Ruby runtime = context.runtime; if (noreverse == runtime.getTrue()) { return false; } else if (noreverse == runtime.getFalse()) { return true; } else if (noreverse == context.nil) { return null; } else { TypeConverter.checkType(context, noreverse, runtime.getSymbol()); switch (noreverse.toString()) { case "numeric": return true; case "hostname": return false; default: throw runtime.newArgumentError("invalid reverse_lookup flag: " + noreverse); } } }
public static Boolean doReverseLookup(ThreadContext context, IRubyObject noreverse) { Ruby runtime = context.runtime; if (noreverse == runtime.getTrue()) { return false; } else if (noreverse == runtime.getFalse()) { return true; } else if (noreverse == context.nil) { return null; } else { TypeConverter.checkType(context, noreverse, runtime.getSymbol()); switch (noreverse.toString()) { case "numeric": return true; case "hostname": return false; default: throw runtime.newArgumentError("invalid reverse_lookup flag: " + noreverse); } } }
@JRubyMethod(name = "to_proc") public RubyProc to_proc(ThreadContext context) { IRubyObject newProc = getOrCreateRubyHashMap().callMethod("to_proc"); TypeConverter.checkType(context, newProc, context.runtime.getProc()); return (RubyProc) newProc; }
@JRubyMethod(name = "to_proc") public RubyProc to_proc(ThreadContext context) { IRubyObject newProc = getOrCreateRubyHashMap().callMethod("to_proc"); TypeConverter.checkType(context, newProc, context.runtime.getProc()); return (RubyProc) newProc; }
private static IRubyObject getPatternQuoted(ThreadContext context, IRubyObject pat, boolean check) { IRubyObject val; if (pat instanceof RubyRegexp) return pat; if (!(pat instanceof RubyString)) { val = pat.checkStringType(); if (val == context.nil) { TypeConverter.checkType(context, pat, context.runtime.getRegexp()); } pat = val; } if (check && ((RubyString) pat).isBrokenString()) { // MRI code does a raise of TypeError with a special regexp string constructor that raises RegexpError throw context.runtime.newRegexpError("invalid byte sequence in " + ((RubyString) pat).getEncoding()); } return pat; }
private static IRubyObject getPatternQuoted(ThreadContext context, IRubyObject pat, boolean check) { IRubyObject val; if (pat instanceof RubyRegexp) return pat; if (!(pat instanceof RubyString)) { val = pat.checkStringType(); if (val == context.nil) { TypeConverter.checkType(context, pat, context.runtime.getRegexp()); } pat = val; } if (check && ((RubyString) pat).isBrokenString()) { // MRI code does a raise of TypeError with a special regexp string constructor that raises RegexpError throw context.runtime.newRegexpError("invalid byte sequence in " + ((RubyString) pat).getEncoding()); } return pat; }
@JRubyMethod public static IRubyObject warn(ThreadContext context, IRubyObject recv, IRubyObject arg) { Ruby runtime = context.runtime; if (!runtime.warningsEnabled()) return context.nil; TypeConverter.checkType(context, arg, runtime.getString()); RubyString str = (RubyString) arg; if (!str.getEncoding().isAsciiCompatible()) { throw runtime.newEncodingCompatibilityError("ASCII incompatible encoding: " + str.getEncoding()); } writeWarningToError(runtime.getCurrentContext(), str); return context.nil; }
@JRubyMethod public static IRubyObject warn(ThreadContext context, IRubyObject recv, IRubyObject arg) { Ruby runtime = context.runtime; if (!runtime.warningsEnabled()) return context.nil; TypeConverter.checkType(context, arg, runtime.getString()); RubyString str = (RubyString) arg; if (!str.getEncoding().isAsciiCompatible()) { throw runtime.newEncodingCompatibilityError("ASCII incompatible encoding: " + str.getEncoding()); } writeWarningToError(runtime.getCurrentContext(), str); return context.nil; }