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
    • pre

      private final short pre
    • opt

      private final short opt
    • rest

      private final Signature.Rest rest
    • post

      private final short post
    • kwargs

      private final short kwargs
    • requiredKwargs

      private final short requiredKwargs
    • arityValue

      private final int arityValue
    • keyRest

      private final int keyRest
    • MAX_ENCODED_ARGS_EXPONENT

      private static final int MAX_ENCODED_ARGS_EXPONENT
      See Also:
    • MAX_ENCODED_ARGS_MASK

      private static final int MAX_ENCODED_ARGS_MASK
      See Also:
    • ENCODE_RESTKWARGS_SHIFT

      private static final int ENCODE_RESTKWARGS_SHIFT
      See Also:
    • ENCODE_REST_SHIFT

      private static final int ENCODE_REST_SHIFT
      See Also:
    • ENCODE_REQKWARGS_SHIFT

      private static final int ENCODE_REQKWARGS_SHIFT
      See Also:
    • ENCODE_KWARGS_SHIFT

      private static final int ENCODE_KWARGS_SHIFT
      See Also:
    • ENCODE_POST_SHIFT

      private static final int ENCODE_POST_SHIFT
      See Also:
    • ENCODE_OPT_SHIFT

      private static final int ENCODE_OPT_SHIFT
      See Also:
    • ENCODE_PRE_SHIFT

      private static final int ENCODE_PRE_SHIFT
      See Also:
  • 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()
    • 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)
    • restFromArg

      private static Signature.Rest restFromArg(Node restArg)
    • 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

      public void checkArity(Ruby runtime, IRubyObject[] args)
    • equals

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