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

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

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

Block.arity介绍

[英]What is the arity of this block?
[中]这个街区的面积是多少?

代码示例

代码示例来源: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_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(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.kill-bill.billing/killbill-osgi-bundles-jruby

@Override
public Arity getArity() {
  return proc.getBlock().arity();
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@JRubyMethod(name = "find_index", compat = RUBY1_9)
public static IRubyObject find_index19(ThreadContext context, IRubyObject self, final Block block) {
  return find_index(context, self, block, block.arity());
}

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

@JRubyMethod(name = "one?", compat = RUBY1_9)
public static IRubyObject one_p19(ThreadContext context, IRubyObject self, final Block block) {
  return one_p(context, self, block, block.arity());
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@JRubyMethod(name = "count", compat = CompatVersion.RUBY1_9)
public static IRubyObject count(ThreadContext context, IRubyObject self, final Block block) {
  return countCommon(context, self, block, block.arity());
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@JRubyMethod(name = "none?", compat = RUBY1_9)
public static IRubyObject none_p19(ThreadContext context, IRubyObject self, final Block block) {
  return none_p(context, self, block, block.arity());
}

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

@JRubyMethod(name = "find_index", compat = RUBY1_9)
public static IRubyObject find_index19(ThreadContext context, IRubyObject self, final Block block) {
  return find_index(context, self, block, block.arity());
}

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

@JRubyMethod(name = "none?", compat = RUBY1_9)
public static IRubyObject none_p19(ThreadContext context, IRubyObject self, final Block block) {
  return none_p(context, self, block, block.arity());
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@JRubyMethod(name = "all?", compat = RUBY1_9)
public static IRubyObject all_p19(ThreadContext context, IRubyObject self, final Block block) {
  if (self instanceof RubyArray) return ((RubyArray) self).all_p(context, block);
  return all_pCommon(context, self, block, block.arity());
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@JRubyMethod(name = {"call", "[]", "yield", "==="}, rest = true, compat = RUBY1_9)
public IRubyObject call19(ThreadContext context, IRubyObject[] args, Block blockCallArg) {
  if (isLambda()) {
    block.arity().checkArity(context.runtime, args.length);
  }
  if (isProc()) args = prepareProcArgs(context, block.arity(), args);
  return call(context, args, null, blockCallArg);
}

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

@JRubyMethod(name = {"call", "[]", "yield", "==="}, rest = true, compat = RUBY1_9)
public IRubyObject call19(ThreadContext context, IRubyObject[] args, Block blockCallArg) {
  if (isLambda()) {
    block.arity().checkArity(context.runtime, args.length);
  }
  if (isProc()) args = prepareProcArgs(context, block.arity(), args);
  return call(context, args, null, blockCallArg);
}

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

public static IRubyObject unsplatValue19IfArityOne(IRubyObject argsResult, Block block) {
  if (block.isGiven() && block.arity().getValue() > 1) argsResult = Helpers.unsplatValue19(argsResult);
  return argsResult;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@JRubyMethod(name = "any?", compat = CompatVersion.RUBY1_9)
public static IRubyObject any_p(ThreadContext context, IRubyObject self, final Block block) {
  if (self instanceof RubyArray) return ((RubyArray) self).any_p(context, block);
  return any_pCommon(context, self, block, block.arity());
}

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

@JRubyMethod(name = "any?", compat = CompatVersion.RUBY1_9)
public static IRubyObject any_p(ThreadContext context, IRubyObject self, final Block block) {
  if (self instanceof RubyArray) return ((RubyArray) self).any_p(context, block);
  return any_pCommon(context, self, block, block.arity());
}

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

@JRubyMethod(name = "all?", compat = RUBY1_9)
public static IRubyObject all_p19(ThreadContext context, IRubyObject self, final Block block) {
  if (self instanceof RubyArray) return ((RubyArray) self).all_p(context, block);
  return all_pCommon(context, self, block, block.arity());
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@JRubyMethod(name = "arity")
public RubyFixnum arity() {
  return getRuntime().newFixnum(block.arity().getValue());
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

/** default_proc_arity_check
 *
 */
private void checkDefaultProcArity(IRubyObject proc) {
  int n = ((RubyProc)proc).getBlock().arity().getValue();
  if(((RubyProc)proc).getBlock().type == Block.Type.LAMBDA && n != 2 && (n >= 0 || n < -3)) {
    if(n < 0) n = -n-1;
    throw getRuntime().newTypeError("default_proc takes two arguments (2 for " + n + ")");
  }
}

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

/** default_proc_arity_check
 *
 */
private void checkDefaultProcArity(IRubyObject proc) {
  int n = ((RubyProc)proc).getBlock().arity().getValue();
  if(((RubyProc)proc).getBlock().type == Block.Type.LAMBDA && n != 2 && (n >= 0 || n < -3)) {
    if(n < 0) n = -n-1;
    throw getRuntime().newTypeError("default_proc takes two arguments (2 for " + n + ")");
  }
}

相关文章