本文整理了Java中org.jruby.runtime.Block.isGiven()
方法的一些代码示例,展示了Block.isGiven()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.isGiven()
方法的具体详情如下:
包路径:org.jruby.runtime.Block
类名称:Block
方法名:isGiven
[英]Is the current block a real yield'able block instead a null one
[中]当前块是一个真正的可产出块,而不是一个空块吗
代码示例来源:origin: bazelbuild/bazel
@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();
}
代码示例来源:origin: org.jruby/jruby-complete
@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;
}
代码示例来源:origin: org.jruby/jruby-complete
@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);
}
代码示例来源:origin: org.jruby/jruby-complete
@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);
}
}
代码示例来源:origin: org.jruby/jruby-complete
/** 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;
}
代码示例来源:origin: org.jruby/jruby-complete
/** 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);
}
代码示例来源:origin: org.jruby/jruby-complete
@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;
}
代码示例来源:origin: org.jruby/jruby-complete
@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);
}
代码示例来源:origin: org.jruby/jruby-complete
@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;
}
代码示例来源:origin: org.jruby/jruby-complete
@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");
}
}
代码示例来源:origin: org.jruby/jruby-complete
@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());
}
代码示例来源:origin: org.jruby/jruby-core
@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;
}
代码示例来源:origin: bazelbuild/bazel
@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();
}
代码示例来源:origin: org.jruby/jruby-complete
/** 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);
}
代码示例来源:origin: org.jruby/jruby-core
@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);
}
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
@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");
}
}
代码示例来源:origin: org.jruby/jruby-complete
@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));
}
代码示例来源:origin: org.jruby/jruby-complete
/** 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);
}
代码示例来源:origin: org.jruby/jruby-complete
@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");
}
代码示例来源:origin: org.jruby/jruby-core
@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;
}
内容来源于网络,如有侵权,请联系作者删除!