本文整理汇总了Java中org.jruby.runtime.Block.yield方法的典型用法代码示例。如果您正苦于以下问题:Java Block.yield方法的具体用法?Java Block.yield怎么用?Java Block.yield使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jruby.runtime.Block
的用法示例。
在下文中一共展示了Block.yield方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: each
import org.jruby.runtime.Block; //导入方法依赖的package包/类
/**
* This is an implementation of the each method which opens up the Enumerable interface,
* and makes it very convenient to iterate over the elements of a DataBag. Note that currently,
* due to a deficiency in JRuby, it is not possible to call each without a block given.
*
* @param context the context the method is being executed in
* @param block a block to call on the elements of the bag
* @return enumerator object if null block given, nil otherwise
*/
@JRubyMethod
public IRubyObject each(ThreadContext context, Block block) throws ExecException{
Ruby runtime = context.getRuntime();
if (!block.isGiven())
return PigJrubyLibrary.enumeratorize(runtime, this, "each");
/* In a future release of JRuby when enumeratorize is made public (which is planned), should replace the above with the below
if (!block.isGiven())
return RubyEnumerator.enumeratorize(context.getRuntime(), this, "each");
*/
for (Tuple t : this)
block.yield(context, PigJrubyLibrary.pigToRuby(runtime, t));
return context.nil;
}
示例2: flatten
import org.jruby.runtime.Block; //导入方法依赖的package包/类
/**
* This is a convenience method which will run the given block on the first element
* of each tuple contained.
*
* @param context the context the method is being executed in
* @param block a block to call on the elements of the bag
* @return enumerator object if null block given, nil otherwise
*/
@JRubyMethod(name = {"flat_each", "flatten"})
public IRubyObject flatten(ThreadContext context, Block block) throws ExecException {
Ruby runtime = context.getRuntime();
if (!block.isGiven())
return PigJrubyLibrary.enumeratorize(runtime, this, "flatten");
/* In a future release of JRuby when enumeratorize is made public (which is planned), should replace the above with the below
if (!block.isGiven())
return RubyEnumerator.enumeratorize(context.getRuntime(), this, "flatten");
*/
for (Tuple t : this)
block.yield(context, PigJrubyLibrary.pigToRuby(runtime, t.get(0)));
return context.nil;
}
示例3: each
import org.jruby.runtime.Block; //导入方法依赖的package包/类
@JRubyMethod
public IRubyObject each(ThreadContext context, Block block) {
if (!block.isGiven()) return enumeratorize(context.runtime, this, "each");
for(int i=0; i < cnt; i++) {
block.yield(context, nth(context, RubyFixnum.newFixnum(context.runtime, i)));
}
return this;
}
示例4: each
import org.jruby.runtime.Block; //导入方法依赖的package包/类
@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();
}
示例5: each
import org.jruby.runtime.Block; //导入方法依赖的package包/类
@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();
}
示例6: each
import org.jruby.runtime.Block; //导入方法依赖的package包/类
@JRubyMethod public IRubyObject each(ThreadContext context, Block block) {
IRubyObject nil = getRuntime().getNil();
IRubyObject line;
while ((line = gets()) != nil) {
block.yield(context, line);
}
return nil;
}