@JRubyMethod(name = "==") public IRubyObject eq(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (!(other instanceof RubyMessage)) return runtime.getFalse(); RubyMessage message = (RubyMessage) other; if (descriptor != message.descriptor) { return runtime.getFalse(); } for (Descriptors.FieldDescriptor fdef : descriptor.getFields()) { IRubyObject thisVal = getField(context, fdef); IRubyObject thatVal = message.getField(context, fdef); IRubyObject ret = thisVal.callMethod(context, "==", thatVal); if (!ret.isTrue()) { return runtime.getFalse(); } } return runtime.getTrue(); }
public static IRubyObject convert2ptr(ThreadContext context, IRubyObject parameter) { final int MAXRECURSE = 4; IRubyObject ptr = parameter; for (int i = 0; i < MAXRECURSE && !(ptr instanceof AbstractMemory) && ptr.respondsTo("to_ptr"); i++) { ptr = ptr.callMethod(context, "to_ptr"); } return ptr; }
@Override public void register(IRubyObject registry) { registry.callMethod(rubyRuntime.getCurrentContext(), "postprocessor", rubyClass); } });
@Override public IRubyObject get() { IRubyObject errorInfo = runtime.getGlobalVariables().get("$!"); IRubyObject backtrace = errorInfo.isNil() ? runtime.getNil() : errorInfo.callMethod(errorInfo.getRuntime().getCurrentContext(), "backtrace"); //$@ returns nil if $!.backtrace is not an array if (!(backtrace instanceof RubyArray)) { backtrace = runtime.getNil(); } return backtrace; }
@JRubyMethod public static IRubyObject initialize(IRubyObject self, IRubyObject type_id, IRubyObject val, IRubyObject style) { Ruby runtime = self.getRuntime(); ThreadContext ctx = runtime.getCurrentContext(); ((RubyObject)self).fastSetInstanceVariable("@kind", ((Node)self).x.scalar); self.callMethod(ctx, "type_id=", type_id); self.callMethod(ctx, "value=", val); self.callMethod(ctx, "style=", style); return self; }
@JRubyMethod(name = "readbyte") public static IRubyObject readbyte(ThreadContext context, IRubyObject self) { IRubyObject b = self.callMethod(context, "getbyte"); if (b.isNil()) throw context.runtime.newEOFError(); return b; }
@Deprecated public static IRubyObject convertToType(IRubyObject obj, RubyClass target, int convertMethodIndex, String convertMethod, boolean raise) { if (!obj.respondsTo(convertMethod)) return handleUncoercibleObject(raise, obj, target); return obj.callMethod(obj.getRuntime().getCurrentContext(), convertMethod); }
@JRubyMethod(name="bufsize=") public static IRubyObject bufsize_set(IRubyObject self, IRubyObject size) { if(size.respondsTo("to_i")) { int n = RubyNumeric.fix2int(size.callMethod(self.getRuntime().getCurrentContext(), "to_i")); Parser p = (Parser)self.dataGetStructChecked(); p.bufsize = n; } return self; }
@JRubyMethod public synchronized IRubyObject rewind(ThreadContext context) { if (object.respondsTo("rewind")) object.callMethod(context, "rewind"); if (nexter != null) { nexter.shutdown(); nexter = null; } return this; }
private final IRubyObject unwrapCoerced(ThreadContext context, String method, IRubyObject other, RubyArray ary) { IRubyObject result = (ary.eltInternal(0)).callMethod(context, method, ary.eltInternal(1)); if (result.isNil()) { return RubyComparable.cmperr(this, other); } return result; }
@Override public void register(IRubyObject registry) { registry.callMethod(rubyRuntime.getCurrentContext(), "postprocessor", rubyClass); } });
@Override public IRubyObject get() { IRubyObject errorInfo = runtime.getGlobalVariables().get("$!"); IRubyObject backtrace = errorInfo.isNil() ? runtime.getNil() : errorInfo.callMethod(errorInfo.getRuntime().getCurrentContext(), "backtrace"); //$@ returns nil if $!.backtrace is not an array if (!(backtrace instanceof RubyArray)) { backtrace = runtime.getNil(); } return backtrace; }
@Override @JRubyMethod(name = "inspect") public IRubyObject inspect() { final ThreadContext context = getRuntime().getCurrentContext(); return callMethod(context, "to_a").callMethod(context, "inspect"); } }// RubyClassPathVariable
@JRubyMethod(name = "digest!") public static IRubyObject digest_bang(ThreadContext context, IRubyObject self) { IRubyObject value = self.callMethod(context, "finish"); self.callMethod(context, "reset"); return value; }
@JRubyMethod(name = "readchar") public static IRubyObject readchar(ThreadContext context, IRubyObject self) { IRubyObject c = self.callMethod(context, "getc"); if (c.isNil()) throw context.runtime.newEOFError(); return c; }
@Deprecated public static IRubyObject convertToType(IRubyObject obj, RubyClass target, int convertMethodIndex, String convertMethod, boolean raise) { if (!obj.respondsTo(convertMethod)) return handleUncoercibleObject(raise, obj, target); return obj.callMethod(obj.getRuntime().getCurrentContext(), convertMethod); }
public static IRubyObject convert2ptr(ThreadContext context, IRubyObject parameter) { final int MAXRECURSE = 4; IRubyObject ptr = parameter; for (int i = 0; i < MAXRECURSE && !(ptr instanceof AbstractMemory) && ptr.respondsTo("to_ptr"); i++) { ptr = ptr.callMethod(context, "to_ptr"); } return ptr; }
@JRubyMethod public static IRubyObject add(IRubyObject self, IRubyObject key, IRubyObject val) { IRubyObject emitter = (IRubyObject)((RubyObject)self).fastGetInstanceVariable("@emitter"); org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked(); if(emitter.respondsTo("node_export")) { key = emitter.callMethod(self.getRuntime().getCurrentContext(), "node_export", key); val = emitter.callMethod(self.getRuntime().getCurrentContext(), "node_export", val); } node.mapAdd(key, val); ((RubyHash)((RubyObject)self).fastGetInstanceVariable("@value")).fastASet(key, val); return self; }
@JRubyMethod public synchronized IRubyObject rewind(ThreadContext context) { if (object.respondsTo("rewind")) object.callMethod(context, "rewind"); if (nexter != null) { nexter.shutdown(); nexter = null; } return this; }
private final IRubyObject unwrapCoerced(ThreadContext context, String method, IRubyObject other, RubyArray ary) { IRubyObject result = (ary.eltInternal(0)).callMethod(context, method, ary.eltInternal(1)); if (result.isNil()) { return RubyComparable.cmperr(this, other); } return result; }