org.jruby.runtime.Block.yield()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(165)

本文整理了Java中org.jruby.runtime.Block.yield()方法的一些代码示例,展示了Block.yield()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.yield()方法的具体详情如下:
包路径:org.jruby.runtime.Block
类名称:Block
方法名:yield

Block.yield介绍

暂无

代码示例

代码示例来源:origin: bazelbuild/bazel

@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();
}

代码示例来源:origin: bazelbuild/bazel

@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();
}

代码示例来源: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 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;
}

代码示例来源: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

public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
    IRubyObject packedArg = packEnumValues(context.runtime, args);
    if (block.yield(context, packedArg).isTrue()) result[0]++;
    return context.nil;
  }
});

代码示例来源:origin: org.jruby/jruby-complete

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;
}

代码示例来源:origin: org.jruby/jruby-complete

public static IRubyObject ensureYieldClose(ThreadContext context, IRubyObject port, Block block) {
  if (block.isGiven()) {
    try {
      return block.yield(context, port);
    } finally {
      ioClose(context, port);
    }
  }
  return port;
}

代码示例来源:origin: org.jruby/jruby-core

@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;
}

代码示例来源: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-core

public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
    IRubyObject packedArg = packEnumValues(context.runtime, args);
    if (block.yield(context, packedArg).isTrue()) result[0]++;
    return context.nil;
  }
});

代码示例来源:origin: org.jruby/jruby-core

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;
}

代码示例来源: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: bazelbuild/bazel

@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();
}

代码示例来源:origin: org.jruby/jruby-complete

static IRubyObject wrapBlock(ThreadContext context, RubyGzipFile instance, Block block) {
  if (block.isGiven()) {
    try {
      return block.yield(context, instance);
    } finally {
      if (!instance.isClosed()) {
        instance.close();
      }
    }
  }
  return instance;
}

代码示例来源:origin: org.jruby/jruby-complete

@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);
  }
}

代码示例来源: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

public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
    checkContext(context, ctx, "none?");
    IRubyObject larg = packEnumValues(ctx, largs);
    if (block.yield(ctx, larg).isTrue()) throw JumpException.SPECIAL_JUMP;
    return ctx.nil;
  }
});

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

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();
}

代码示例来源:origin: org.jruby/jruby-complete

@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;
}

相关文章