当前位置: 首页>>代码示例>>Java>>正文


Java Block.yield方法代码示例

本文整理汇总了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;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:26,代码来源:RubyDataBag.java

示例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;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:25,代码来源:RubyDataBag.java

示例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;
}
 
开发者ID:Who828,项目名称:persistent_data_structures,代码行数:10,代码来源:PersistentVectorLibrary.java

示例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();
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:10,代码来源:RubyEnumDescriptor.java

示例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();
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:8,代码来源:RubyDescriptor.java

示例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;
}
 
开发者ID:square,项目名称:rack-servlet,代码行数:9,代码来源:JRubyRackInput.java


注:本文中的org.jruby.runtime.Block.yield方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。