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

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

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

Block.getSignature介绍

暂无

代码示例

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

/**
 * What is the arity of this block?
 *
 * @return the arity
 */
@Deprecated
public Arity arity() {
  return getSignature().arity();
}

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

private static void checkArity(ThreadContext context, Block selfBlock, IRubyObject[] args, Block block) {
  if (selfBlock.type == Block.Type.LAMBDA) {
    selfBlock.getSignature().checkArity(context.runtime, args);
  }
}

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

private static void checkArity(ThreadContext context, Block selfBlock, IRubyObject[] args, Block block) {
  if (selfBlock.type == Block.Type.LAMBDA) {
    selfBlock.getSignature().checkArity(context.runtime, args);
  }
}

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

/**
 * What is the arity of this block?
 *
 * @return the arity
 */
@Deprecated
public Arity arity() {
  return getSignature().arity();
}

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

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

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

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

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

private IRubyObject[] adjustArgs(Block block, IRubyObject[] args) {
  Signature signature = block.getSignature();
  int required = signature.required();
  if (signature.isFixed() && required  > 0 && required < args.length) args = ArraySupport.newCopy(args, required);
  return args;
}

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

private IRubyObject[] adjustArgs(Block block, IRubyObject[] args) {
  Signature signature = block.getSignature();
  int required = signature.required();
  if (signature.isFixed() && required  > 0 && required < args.length) args = ArraySupport.newCopy(args, required);
  return args;
}

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

private IRubyObject[] adjustArgs(Block block, IRubyObject[] args) {
  Signature signature = block.getSignature();
  int required = signature.required();
  if (signature.isFixed() && required  > 0 && required < args.length) args = ArraySupport.newCopy(args, required);
  return args;
}

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

private IRubyObject[] adjustArgs(Block block, IRubyObject[] args) {
  Signature signature = block.getSignature();
  int required = signature.required();
  if (signature.isFixed() && required  > 0 && required < args.length) args = ArraySupport.newCopy(args, required);
  return args;
}

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

/** default_proc_arity_check
 *
 */
private void checkDefaultProcArity(IRubyObject proc) {
  int n = ((RubyProc)proc).getBlock().getSignature().arityValue();
  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: org.jruby/jruby-complete

@JRubyMethod(name = "find_index")
public static IRubyObject find_index(ThreadContext context, IRubyObject self, final Block block) {
  boolean blockGiven = block.isGiven();
  if (self instanceof RubyArray && blockGiven) return ((RubyArray) self).find_index(context, block);
  return blockGiven ? find_indexCommon(context, self, block, block.getSignature()) :
      enumeratorize(context.runtime, self, "find_index");
}

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

/** default_proc_arity_check
 *
 */
private void checkDefaultProcArity(IRubyObject proc) {
  int n = ((RubyProc)proc).getBlock().getSignature().arityValue();
  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: org.jruby/jruby-core

@JRubyMethod(name = "find_index")
public static IRubyObject find_index(ThreadContext context, IRubyObject self, final Block block) {
  boolean blockGiven = block.isGiven();
  if (self instanceof RubyArray && blockGiven) return ((RubyArray) self).find_index(context, block);
  return blockGiven ? find_indexCommon(context, self, block, block.getSignature()) :
      enumeratorize(context.runtime, self, "find_index");
}

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

@Override // re-invent @JRubyMethod(name = "any?")
public IRubyObject any_p(ThreadContext context, IRubyObject[] args, Block block) {
  boolean patternGiven = args.length > 0;
  if (isEmpty()) return context.fals;
  if (!block.isGiven() && !patternGiven) return context.tru;
  if (patternGiven) return any_p_p(context, args[0]);
  if (block.getSignature().arityValue() > 1) {
    return any_p_i_fast(context, block);
  }
  return any_p_i(context, block);
}

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

@Override // re-invent @JRubyMethod(name = "any?")
public IRubyObject any_p(ThreadContext context, IRubyObject[] args, Block block) {
  boolean patternGiven = args.length > 0;
  if (isEmpty()) return context.fals;
  if (!block.isGiven() && !patternGiven) return context.tru;
  if (patternGiven) return any_p_p(context, args[0]);
  if (block.getSignature().arityValue() > 1) {
    return any_p_i_fast(context, block);
  }
  return any_p_i(context, block);
}

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

@JRubyMethod(name = "any?", optional = 1)
public IRubyObject any_p(ThreadContext context, IRubyObject[] args, Block block) {
  IRubyObject pattern = args.length > 0 ? args[0] : null;
  boolean patternGiven = pattern != null;
  if (isEmpty()) return context.fals;
  if (!block.isGiven() && !patternGiven) return context.tru;
  if (patternGiven) return any_p_p(context, pattern);
  if (block.getSignature().arityValue() > 1) {
    return any_p_i_fast(context, block);
  }
  return any_p_i(context, block);
}

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

@JRubyMethod(name = "any?", optional = 1)
public IRubyObject any_p(ThreadContext context, IRubyObject[] args, Block block) {
  IRubyObject pattern = args.length > 0 ? args[0] : null;
  boolean patternGiven = pattern != null;
  if (isEmpty()) return context.fals;
  if (!block.isGiven() && !patternGiven) return context.tru;
  if (patternGiven) return any_p_p(context, pattern);
  if (block.getSignature().arityValue() > 1) {
    return any_p_i_fast(context, block);
  }
  return any_p_i(context, block);
}

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

@JRubyMethod(name = "arity")
public RubyFixnum arity() {
  Signature signature = block.getSignature();
  if (block.type == Block.Type.LAMBDA) return getRuntime().newFixnum(signature.arityValue());
  // FIXME: Consider min/max like MRI here instead of required + kwarg count.
  return getRuntime().newFixnum(signature.hasRest() ? signature.arityValue() : signature.required() + signature.getRequiredKeywordForArityCount());
}

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

@JRubyMethod(name = "arity")
public RubyFixnum arity() {
  Signature signature = block.getSignature();
  if (block.type == Block.Type.LAMBDA) return getRuntime().newFixnum(signature.arityValue());
  // FIXME: Consider min/max like MRI here instead of required + kwarg count.
  return getRuntime().newFixnum(signature.hasRest() ? signature.arityValue() : signature.required() + signature.getRequiredKeywordForArityCount());
}

相关文章