/** * Return true if the given object responds to "begin" and "end" methods. * * @param context current context * @param obj possibly range-like object * @param respond_to_begin respond_to? site for begin * @param respond_to_end respond_to? site for end * @return */ public static boolean isRangeLike(ThreadContext context, IRubyObject obj, RespondToCallSite respond_to_begin, RespondToCallSite respond_to_end) { return respond_to_begin.respondsTo(context, obj, obj) && respond_to_end.respondsTo(context, obj, obj); }
/** * Return true if the given object responds to "begin" and "end" methods. * * @param context current context * @param obj possibly range-like object * @param respond_to_begin respond_to? site for begin * @param respond_to_end respond_to? site for end * @return */ public static boolean isRangeLike(ThreadContext context, IRubyObject obj, RespondToCallSite respond_to_begin, RespondToCallSite respond_to_end) { return respond_to_begin.respondsTo(context, obj, obj) && respond_to_end.respondsTo(context, obj, obj); }
private static boolean discreteObject(ThreadContext context, IRubyObject obj) { if (obj instanceof RubyTime) return false; return sites(context).respond_to_succ.respondsTo(context, obj, obj, false); }
private static boolean discreteObject(ThreadContext context, IRubyObject obj) { if (obj instanceof RubyTime) return false; return sites(context).respond_to_succ.respondsTo(context, obj, obj, false); }
@JRubyMethod(name = "try_convert", meta = true) public static IRubyObject tryConvert(ThreadContext context, IRubyObject recv, IRubyObject arg) { return ( arg instanceof RubyObject && sites(context).respond_to_to_io.respondsTo(context, arg, arg, true) ) ? convertToIO(context, arg) : context.nil; }
@JRubyMethod(name = "try_convert", meta = true) public static IRubyObject tryConvert(ThreadContext context, IRubyObject recv, IRubyObject arg) { return ( arg instanceof RubyObject && sites(context).respond_to_to_io.respondsTo(context, arg, arg, true) ) ? convertToIO(context, arg) : context.nil; }
private static void setBinmodeIfPossible(ThreadContext context, IRubyObject io) { if (sites(context).respond_to_binmode.respondsTo(context, io, io)) { sites(context).binmode.call(context, io, io); } }
public boolean isOpen() { ThreadContext context = runtime.getCurrentContext(); if (respondToClosed.respondsTo(context, io, io)) { return !isClosedAdapter.call(context, io, io).isTrue(); } // can't determine, assume it's open return true; }
private static void setBinmodeIfPossible(ThreadContext context, IRubyObject io) { if (sites(context).respond_to_binmode.respondsTo(context, io, io)) { sites(context).binmode.call(context, io, io); } }
public boolean isOpen() { ThreadContext context = runtime.getCurrentContext(); if (respondToClosed.respondsTo(context, io, io)) { return !isClosedAdapter.call(context, io, io).isTrue(); } // can't determine, assume it's open return true; }
public static RubyString get_path(ThreadContext context, IRubyObject path) { if (path instanceof RubyString) return (RubyString) path; FileSites sites = sites(context); if (sites.respond_to_to_path.respondsTo(context, path, path, true)) path = sites.to_path.call(context, path, path); return filePathConvert(context, path.convertToString()); }
public static RubyString get_path(ThreadContext context, IRubyObject path) { if (path instanceof RubyString) return (RubyString) path; FileSites sites = sites(context); if (sites.respond_to_to_path.respondsTo(context, path, path, true)) path = sites.to_path.call(context, path, path); return filePathConvert(context, path.convertToString()); }
private static int argToInt(final ThreadContext context, IRubyObject[] args, final int i, final int def) { IRubyObject arg = args[i]; if (arg != context.nil) { if (!(arg instanceof RubyNumeric)) { final TimeSites sites = sites(context); if (sites.respond_to_to_int.respondsTo(context, arg, arg)) { arg = args[i] = sites.to_int.call(context, arg, arg); } else { arg = args[i] = sites.to_i.call(context, arg, arg); } } return RubyNumeric.num2int(arg); } return def; }
private static int argToInt(final ThreadContext context, IRubyObject[] args, final int i, final int def) { IRubyObject arg = args[i]; if (arg != context.nil) { if (!(arg instanceof RubyNumeric)) { final TimeSites sites = sites(context); if (sites.respond_to_to_int.respondsTo(context, arg, arg)) { arg = args[i] = sites.to_int.call(context, arg, arg); } else { arg = args[i] = sites.to_i.call(context, arg, arg); } } return RubyNumeric.num2int(arg); } return def; }
/** do_coerce * */ protected final RubyArray doCoerce(ThreadContext context, IRubyObject other, boolean err) { if (!sites(context).respond_to_coerce.respondsTo(context, other, other)) { if (err) { coerceFailed(context, other); } return null; } final IRubyObject $ex = context.getErrorInfo(); final IRubyObject result; result = coerceBody(context, other); return coerceResult(context.runtime, result, err); }
/** rb_ary_equal * */ @JRubyMethod(name = "==", required = 1) @Override public IRubyObject op_equal(ThreadContext context, IRubyObject obj) { if (this == obj) return context.tru; if (!(obj instanceof RubyArray)) { if (obj == context.nil) return context.fals; if (!sites(context).respond_to_to_ary.respondsTo(context, obj, obj)) { return context.fals; } return Helpers.rbEqual(context, obj, this); } return RecursiveComparator.compare(context, sites(context).op_equal, this, obj); }
public RubyBoolean compare(ThreadContext context, CallSite site, IRubyObject other) { if (!(other instanceof RubyArray)) { if (!sites(context).respond_to_to_ary.respondsTo(context, other, other)) return context.fals; return Helpers.rbEqual(context, other, this); } RubyArray ary = (RubyArray) other; if (realLength != ary.realLength) return context.fals; for (int i = 0; i < realLength; i++) { IRubyObject a = elt(i); IRubyObject b = ary.elt(i); if (a == b) continue; // matching MRI opt. mock frameworks can throw errors if we don't if (!site.call(context, a, a, b).isTrue()) return context.fals; } return context.tru; }
private IRubyObject op_equalCommon(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (!sites(context).respond_to_to_str.respondsTo(context, this, other)) return runtime.getFalse(); return sites(context).equals.call(context, this, other, this).isTrue() ? runtime.getTrue() : runtime.getFalse(); }
private IRubyObject op_equalCommon(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (!sites(context).respond_to_to_str.respondsTo(context, this, other)) return runtime.getFalse(); return sites(context).equals.call(context, this, other, this).isTrue() ? runtime.getTrue() : runtime.getFalse(); }
@JRubyMethod(name = "<=>") @Override public IRubyObject op_cmp(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (other instanceof RubyString) { return runtime.newFixnum(op_cmp((RubyString)other)); } JavaSites.CheckedSites sites = sites(context).to_str_checked; if (sites.respond_to_X.respondsTo(context, this, other)) { IRubyObject tmp = TypeConverter.checkStringType(context, sites, other); if (tmp instanceof RubyString) return runtime.newFixnum(op_cmp((RubyString) tmp)); } else { return invcmp(context, sites(context).recursive_cmp, this, other); } return context.nil; }