Refine search
@JRubyMethod public IRubyObject each(ThreadContext context, Block block) { for (Map.Entry<String, RubyFieldDescriptor> entry : fieldDefMap.entrySet()) { block.yield(context, entry.getValue()); } return context.runtime.getNil(); }
@JRubyMethod public IRubyObject build(ThreadContext context, Block block) { RubyBuilder ctx = (RubyBuilder) cBuilder.newInstance(context, Block.NULL_BLOCK); if (block.arity() == Arity.ONE_ARGUMENT) { block.yield(context, ctx); } else { Binding binding = block.getBinding(); binding.setSelf(ctx); block.yieldSpecific(context); } ctx.finalizeToPool(context, this); buildFileDescriptor(context); return context.runtime.getNil(); }
@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 IRubyObject keep_if(final ThreadContext context, Block block) { if ( ! block.isGiven() ) { return enumeratorizeWithSize(context, this, "keep_if", enumSize()); } Iterator<IRubyObject> it = elementsOrdered().iterator(); while ( it.hasNext() ) { IRubyObject elem = it.next(); if ( ! block.yield(context, elem).isTrue() ) deleteImplIterator(elem, it); // it.remove } return this; }
/** 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; }
public IRubyObject all_p(ThreadContext context, IRubyObject[] args, Block block) { if (!isBuiltin("each")) return RubyEnumerable.all_pCommon(context, this, args, block); boolean patternGiven = args.length > 0; if (!block.isGiven() || patternGiven) return all_pBlockless(context, args); for (int i = 0; i < realLength; i++) { if (!block.yield(context, eltOk(i)).isTrue()) return context.fals; } return context.tru; }
@JRubyMethod public IRubyObject keep_if(final ThreadContext context, Block block) { if ( ! block.isGiven() ) { return enumeratorizeWithSize(context, this, "keep_if", enumSize()); } Iterator<IRubyObject> it = elementsOrdered().iterator(); while ( it.hasNext() ) { IRubyObject elem = it.next(); if ( ! block.yield(context, elem).isTrue() ) deleteImplIterator(elem, it); // it.remove } return this; }
@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; }
public IRubyObject all_p(ThreadContext context, IRubyObject[] args, Block block) { if (!isBuiltin("each")) return RubyEnumerable.all_pCommon(context, this, args, block); boolean patternGiven = args.length > 0; if (!block.isGiven() || patternGiven) return all_pBlockless(context, args); for (int i = 0; i < realLength; i++) { if (!block.yield(context, eltOk(i)).isTrue()) return context.fals; } return context.tru; }
@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(); }
@JRubyMethod public IRubyObject each(ThreadContext context, Block block) { Ruby runtime = context.runtime; for (Descriptors.EnumValueDescriptor enumValueDescriptor : descriptor.getValues()) { block.yield(context, runtime.newArray(runtime.newSymbol(enumValueDescriptor.getName()), runtime.newFixnum(enumValueDescriptor.getNumber()))); } return runtime.getNil(); }
@JRubyMethod(name = "count") public IRubyObject count(ThreadContext context, Block block) { if (block.isGiven()) { int n = 0; for (int i = 0; i < realLength; i++) { if (block.yield(context, elt(i)).isTrue()) n++; } return RubyFixnum.newFixnum(context.runtime, n); } else { return RubyFixnum.newFixnum(context.runtime, realLength); } }
@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"); } }
public IRubyObject any_p(ThreadContext context, Block block) { if (!isBuiltin("each")) return RubyEnumerable.any_pCommon(context, this, block, Arity.OPTIONAL); if (!block.isGiven()) return any_pBlockless(context); for (int i = 0; i < realLength; i++) { if (block.yield(context, eltOk(i)).isTrue()) return context.runtime.getTrue(); } return context.runtime.getFalse(); }
@JRubyMethod public static IRubyObject each(final ThreadContext context, final IRubyObject self, final Block block) { final Ruby runtime = context.runtime; java.util.Enumeration enumeration = unwrapIfJavaObject(self); while ( enumeration.hasMoreElements() ) { final Object value = enumeration.nextElement(); block.yield(context, convertJavaToUsableRubyObject(runtime, value)); } return context.nil; }