@JRubyMethod(name = "add_enum") public IRubyObject addEnum(ThreadContext context, IRubyObject name, Block block) { RubyEnumDescriptor enumDef = (RubyEnumDescriptor) cEnumDescriptor.newInstance(context, Block.NULL_BLOCK); IRubyObject ctx = cEnumBuilderContext.newInstance(context, enumDef, Block.NULL_BLOCK); enumDef.setName(context, name); if (block.isGiven()) { if (block.arity() == Arity.ONE_ARGUMENT) { block.yield(context, ctx); } else { Binding binding = block.getBinding(); binding.setSelf(ctx); block.yieldSpecific(context); } } this.pendingList.add(enumDef); return context.runtime.getNil(); }
@JRubyMethod public static IRubyObject each_byte(final ThreadContext context, IRubyObject recv, final Block block) { if (!block.isGiven()) return enumeratorize(context.runtime, recv, "each_byte"); IRubyObject bt; while ((bt = getc(context, recv)) != context.nil) { block.yield(context, bt); } return recv; }
@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); }
@JRubyMethod(module = true) public static IRubyObject yield_self(ThreadContext context, IRubyObject recv, Block block) { if (block.isGiven()) { return block.yield(context, recv); } else { SizeFn enumSizeFn = RubyArray.newArray(context.runtime, context.nil).enumLengthFn(); return RubyEnumerator.enumeratorizeWithSize(context, recv, "yield_self", enumSizeFn); } }
/** rb_hash_delete * */ @JRubyMethod public IRubyObject delete(ThreadContext context, IRubyObject key, Block block) { modify(); final RubyHashEntry entry = internalDelete(key); if (entry != NO_ENTRY) return entry.value; if (block.isGiven()) return block.yield(context, key); return context.nil; }
/** rb_ary_cycle * */ @JRubyMethod(name = "cycle") public IRubyObject cycle(ThreadContext context, Block block) { if (!block.isGiven()) return enumeratorizeWithSize(context, this, "cycle", cycleSizeFn(context)); return cycleCommon(context, -1, block); }
@JRubyMethod public IRubyObject each_char(final ThreadContext context, final Block block) { if (!block.isGiven()) return enumeratorize(context.runtime, this, "each_char"); IRubyObject c; while (!(c = getc(context)).isNil()) { block.yieldSpecific(context, c); } return this; }
@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); }
@JRubyMethod public IRubyObject each(final ThreadContext context, Block block) { if ( ! block.isGiven() ) { return enumeratorizeWithSize(context, this, "each", enumSize()); } for (IRubyObject elem : elementsOrdered()) block.yield(context, elem); return this; }
@JRubyMethod(rest = true, meta = true) public static IRubyObject open(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { IRubyObject tcpServer = recv.callMethod(context, "new", args); if (!block.isGiven()) return tcpServer; try { return block.yield(context, tcpServer); } finally { tcpServer.callMethod(context, "close"); } }
@JRubyMethod(name = "select!") public IRubyObject select_bang(final ThreadContext context, final Block block) { if (block.isGiven()) return keep_ifCommon(context, block) ? this : context.nil; return enumeratorizeWithSize(context, this, "select!", enumSizeFn()); }
@JRubyMethod public static IRubyObject each_byte(final ThreadContext context, IRubyObject recv, final Block block) { if (!block.isGiven()) return enumeratorize(context.runtime, recv, "each_byte"); IRubyObject bt; while ((bt = getc(context, recv)) != context.nil) { block.yield(context, bt); } return recv; }
@JRubyMethod(name = "add_message") public IRubyObject addMessage(ThreadContext context, IRubyObject name, Block block) { RubyDescriptor msgdef = (RubyDescriptor) cDescriptor.newInstance(context, Block.NULL_BLOCK); IRubyObject ctx = cMessageBuilderContext.newInstance(context, msgdef, this, Block.NULL_BLOCK); msgdef.setName(context, name); if (block.isGiven()) { if (block.arity() == Arity.ONE_ARGUMENT) { block.yield(context, ctx); } else { Binding binding = block.getBinding(); binding.setSelf(ctx); block.yieldSpecific(context); } } this.pendingList.add(msgdef); return context.runtime.getNil(); }
/** rb_str_upto_m * */ @JRubyMethod(name = "upto") public final IRubyObject upto(ThreadContext context, IRubyObject end, Block block) { Ruby runtime = context.runtime; return block.isGiven() ? uptoCommon(context, end, false, block) : enumeratorize(runtime, this, "upto", end); }
@JRubyMethod(module = true) public static IRubyObject yield_self(ThreadContext context, IRubyObject recv, Block block) { if (block.isGiven()) { return block.yield(context, recv); } else { SizeFn enumSizeFn = RubyArray.newArray(context.runtime, context.nil).enumLengthFn(); return RubyEnumerator.enumeratorizeWithSize(context, recv, "yield_self", enumSizeFn); } }
@JRubyMethod(rest = true, meta = true) public static IRubyObject open(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { IRubyObject tcpServer = recv.callMethod(context, "new", args); if (!block.isGiven()) return tcpServer; try { return block.yield(context, tcpServer); } finally { tcpServer.callMethod(context, "close"); } }
@JRubyMethod(required = 1) public IRubyObject each_with_object(final ThreadContext context, IRubyObject arg, Block block) { return block.isGiven() ? RubyEnumerable.each_with_objectCommon(context, this, block, arg) : enumeratorizeWithSize(context, this, "each_with_object", new IRubyObject[]{arg}, enumSizeFn(context)); }
/** rb_ary_take_while * */ @JRubyMethod(name = "take_while") public IRubyObject take_while(ThreadContext context, Block block) { Ruby runtime = context.runtime; if (!block.isGiven()) return enumeratorize(runtime, this, "take_while"); int i = 0; for (; i < realLength; i++) { if (!block.yield(context, eltOk(i)).isTrue()) break; } return subseq(0, i); }
@JRubyMethod public static IRubyObject detect(ThreadContext context, IRubyObject self, final Block block) { boolean blockGiven = block.isGiven(); if (self instanceof RubyArray && blockGiven) return ((RubyArray) self).find(context, null, block); return block.isGiven() ? detectCommon(context, self, block) : enumeratorize(context.runtime, self, "detect"); }
@JRubyMethod public IRubyObject each(final ThreadContext context, Block block) { if ( ! block.isGiven() ) { return enumeratorizeWithSize(context, this, "each", enumSize()); } for (IRubyObject elem : elementsOrdered()) block.yield(context, elem); return this; }