Class Signature

java.lang.Object
org.jruby.runtime.Signature

public class Signature extends Object
A representation of a Ruby method signature (argument layout, min/max, keyword layout, rest args).
  • Field Details

    • NO_ARGUMENTS

      public static final Signature NO_ARGUMENTS
    • ONE_ARGUMENT

      public static final Signature ONE_ARGUMENT
    • TWO_ARGUMENTS

      public static final Signature TWO_ARGUMENTS
    • THREE_ARGUMENTS

      public static final Signature THREE_ARGUMENTS
    • FOUR_ARGUMENTS

      public static final Signature FOUR_ARGUMENTS
    • OPTIONAL

      public static final Signature OPTIONAL
    • ONE_REQUIRED

      public static final Signature ONE_REQUIRED
    • TWO_REQUIRED

      public static final Signature TWO_REQUIRED
    • THREE_REQUIRED

      public static final Signature THREE_REQUIRED
    • FOUR_REQUIRED

      public static final Signature FOUR_REQUIRED
    • ONE_OPT_ARGUMENT

      public static final Signature ONE_OPT_ARGUMENT
  • Constructor Details

    • Signature

      public Signature(int pre, int opt, int post, Signature.Rest rest, int kwargs, int requiredKwargs, int keyRest)
  • Method Details

    • getRequiredKeywordForArityCount

      public int getRequiredKeywordForArityCount()
    • restKwargs

      public boolean restKwargs()
    • pre

      public int pre()
    • opt

      public int opt()
    • rest

      public Signature.Rest rest()
    • post

      public int post()
    • hasKwargs

      public boolean hasKwargs()
    • hasRest

      public boolean hasRest()
    • keyRest

      public int keyRest()
    • min

      public int min()
      The minimum number of parameters supplied which can fulfill a call to this signature. This method is for calculating the public-facing arity value.
      Returns:
      the minimum amount of params expected.
    • max

      public int max()
      The maximum number of parameters supplied which can fulfill a call to this signature. This method is for calculating the public-facing arity value.
      Returns:
      the minimum amount of params expected.
    • kwargs

      public int kwargs()
      Total number of keyword argument parameters.
      Returns:
      the number of kwarg parameters
    • isFixed

      public boolean isFixed()
      Are there an exact (fixed) number of parameters to this signature?
    • isNoArguments

      public boolean isNoArguments()
      Is this a signature with a no arguments of any kind?
    • isOneArgument

      public boolean isOneArgument()
      Is this a signature with a single fixed argument and NO keyword arguments?
    • isTwoArguments

      public boolean isTwoArguments()
      Is this a signature with a two fixed arguments and NO keyword arguments?
    • required

      public int required()
    • arity

      @Deprecated public Arity arity()
      Deprecated.
    • calculateArityValue

      public int calculateArityValue()
      Best attempt at breaking the code of arity values! We figure out how many fixed/required parameters must be supplied. Then we figure out if we need to mark the value as optional. Optional is indicated by multiplying -1 * (fixed + 1). Keyword args optional and rest values can indicate this optional condition but only if no required keyword arguments are present.
    • arityValue

      public int arityValue()
    • isSpreadable

      public boolean isSpreadable()
      If we are yield'ing to this signature should we spread/destructure a Ruby Array?
      Returns:
      true if the signature expects multiple args
    • fromArityValue

      public static Signature fromArityValue(int arityValue)
    • from

      @Deprecated public static Signature from(Arity arity)
      Deprecated.
    • from

      public static Signature from(int pre, int opt, int post, int kwargs, int requiredKwargs, Signature.Rest rest, int keyRest)
    • from

      public static Signature from(ArgsNode args)
    • from

      public static Signature from(IterNode iter)
    • from

      public static Signature from(ForNode iter)
    • from

      public static Signature from(PreExeNode iter)
    • from

      public static Signature from(PostExeNode iter)
    • encode

      public long encode()
    • decode

      public static Signature decode(long l)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • checkArity

      @Deprecated(since="10.0") public void checkArity(Ruby runtime, IRubyObject[] args)
      Deprecated.
    • checkArity

      public void checkArity(ThreadContext context, IRubyObject[] args)
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object