@JRubyMethod(rest = true) public IRubyObject each(ThreadContext context, IRubyObject[] args, Block block) { if (args.length == 0) { return each(context, block); } IRubyObject[] newArgs = new IRubyObject[methodArgs.length + args.length]; System.arraycopy(methodArgs, 0, newArgs, 0, methodArgs.length); System.arraycopy(args, 0, newArgs, methodArgs.length, args.length); return new RubyEnumerator(context.runtime, getType(), object, context.runtime.newSymbol("each"), newArgs); }
public void load(final Ruby runtime, boolean wrap) throws IOException { RubyEnumerator.defineEnumerator(runtime); } }
@Override public synchronized boolean hasNext() { return ensureNexter(getRuntime()).hasNext(); }
@JRubyMethod(name = "initialize", rest = true, visibility = PRIVATE, compat = RUBY1_9) public IRubyObject initialize19(ThreadContext context, IRubyObject[] args, Block block) { switch (args.length) { case 0: return initialize19(context, block); case 1: return initialize19(context, args[0], block); case 2: return initialize19(context, args[0], args[1], block); } IRubyObject[] methArgs = new IRubyObject[args.length - 2]; System.arraycopy(args, 2, methArgs, 0, methArgs.length); return initialize(args[0], args[1], methArgs); }
private IRubyObject initialize20(IRubyObject object, IRubyObject method, IRubyObject[] methodArgs, IRubyObject size) { this.object = object; this.method = method.asJavaString(); this.methodArgs = methodArgs; this.size = size; setInstanceVariable("@__object__", object); setInstanceVariable("@__method__", method); setInstanceVariable("@__args__", RubyArray.newArrayNoCopyLight(getRuntime(), methodArgs)); return this; }
@JRubyMethod(rest = true) public IRubyObject each_entry(ThreadContext context, final IRubyObject[] args, final Block block) { return block.isGiven() ? RubyEnumerable.each_entryCommon(context, this, args, block) : enumeratorize(context.runtime, getType(), this, "each_entry", args); }
@JRubyMethod(optional = 1) public IRubyObject each_line(ThreadContext context, IRubyObject[] args, Block block) { if (!block.isGiven()) return RubyEnumerator.enumeratorize(context.runtime, this, "each_line", args); return each(context, args, block); }
ByteList bytes = new ByteList(); bytes.append((byte)'#').append((byte)'<'); bytes.append(getMetaClass().getName().getBytes()); bytes.append((byte)':').append((byte)' '); return RubyString.newStringNoCopy(runtime, bytes).taint(context); } else { boolean tainted = isTaint(); bytes.append(RubyObject.inspect(context, object).getByteList()); bytes.append((byte)':');
private RubyEnumerator(Ruby runtime, RubyClass type, IRubyObject object, IRubyObject method, IRubyObject[] args, IRubyObject size) { super(runtime, type); initialize(runtime, object, method, args, size, null); }
@Override public IRubyObject allocate(Ruby runtime, RubyClass klass) { return new RubyEnumerator(runtime, klass); } };
@JRubyMethod public synchronized IRubyObject peek(ThreadContext context) { final Nexter nexter = ensureNexter(context.runtime); return nexter.peek(); }
@Override public Object next() { return next( getRuntime().getCurrentContext() ).toJava( java.lang.Object.class ); }
@JRubyMethod(name = "inspect") public IRubyObject inspect19(ThreadContext context) { Ruby runtime = context.runtime; if (runtime.isInspecting(this)) return inspect(context, true); try { runtime.registerInspecting(this); return inspect(context, false); } finally { runtime.unregisterInspecting(this); } }
@JRubyMethod(name = "dup") @Override public IRubyObject dup() { // JRUBY-5013: Enumerator needs to copy private fields in order to have a valid structure RubyEnumerator copy = (RubyEnumerator) super.dup(); copy.object = this.object; copy.method = this.method; copy.methodArgs = this.methodArgs; copy.size = this.size; copy.sizeFn = this.sizeFn; copy.feedValue = getRuntime().getNil(); return copy; }
@JRubyMethod(rest = true) public IRubyObject each_entry(ThreadContext context, final IRubyObject[] args, final Block block) { return block.isGiven() ? RubyEnumerable.each_entryCommon(context, this, args, block) : enumeratorize(context.runtime, getType(), this, "each_entry", args); }
@JRubyMethod(name = "each_line") public IRubyObject each_line(ThreadContext context, Block block) { if (!block.isGiven()) return enumeratorize(context.runtime, this, "each_line"); return each(context, block); }
private IRubyObject initialize(IRubyObject object, IRubyObject method, IRubyObject[] methodArgs) { this.object = object; this.method = method.asJavaString(); this.methodArgs = methodArgs; setInstanceVariable("@__object__", object); setInstanceVariable("@__method__", method); setInstanceVariable("@__args__", RubyArray.newArrayNoCopyLight(getRuntime(), methodArgs)); return this; }
ByteList bytes = new ByteList(); bytes.append((byte)'#').append((byte)'<'); bytes.append(getMetaClass().getName().getBytes()); bytes.append((byte)':').append((byte)' '); return RubyString.newStringNoCopy(runtime, bytes).taint(context); } else { boolean tainted = isTaint(); bytes.append(RubyObject.inspect(context, object).getByteList()); bytes.append((byte)':');
@Override public IRubyObject initialize(ThreadContext context) { return initialize(context, Block.NULL_BLOCK); }
@Override public IRubyObject allocate(Ruby runtime, RubyClass klass) { return new RubyEnumerator(runtime, klass); } };