Class Constant

All Implemented Interfaces:
BiVariable

public class Constant extends AbstractVariable
An implementation of BiVariable for a Ruby constant.
  • Field Details

  • Constructor Details

    • Constant

      private Constant(RubyObject receiver, String name, Object... javaObjects)
    • Constant

      Constant(RubyObject receiver, String name, IRubyObject irubyObject)
      A constructor used when constants are retrieved from Ruby.
      Parameters:
      receiver - a receiver object that this variable/constant is originally in. When the variable/constant is originated from Ruby, receiver may not be null.
      name - the constant name
      irubyObject - Ruby constant object
  • Method Details

    • getInstance

      public static BiVariable getInstance(RubyObject receiver, String name, Object... javaObject)
      Returns an instance of this class. This factory method is used when a constant is put in BiVariableMap.
      Parameters:
      receiver - object that this constant/variable is in.
      name - a variable name
      javaObject - Java object that should be assigned to.
      Returns:
      the instance of Constant
    • retrieve

      public static void retrieve(RubyObject receiver, BiVariableMap vars)
      Retrieves constants from Ruby after the evaluation or method invocation.
      Parameters:
      receiver - receiver object returned when a script is evaluated.
      vars - map to save retrieved constants.
    • updateConstantsOfSuperClass

      private static void updateConstantsOfSuperClass(RubyObject receiver, BiVariableMap vars)
    • updateConstants

      private static void updateConstants(RubyObject receiver, BiVariableMap vars)
    • retrieveByKey

      public static void retrieveByKey(RubyObject receiver, BiVariableMap vars, String key)
      Retrieves a constant by key from Ruby runtime after the evaluation. This method is used when eager retrieval is off.
      Parameters:
      receiver - receiver object returned when a script is evaluated.
      vars - map to save retrieved instance variables.
      key - instace varible name
    • getType

      public BiVariable.Type getType()
      Returns enum type of this variable defined in BiVariable.
      Returns:
      this enum type, BiVariable.Type.Constant.
    • isValidName

      public static boolean isValidName(Object name)
      Returns true if the given name is a decent Ruby constant. Unless returns false.
      Parameters:
      name - is a name to be checked.
      Returns:
      true if the given name is of a Ruby constant.
    • inject

      public void inject()
      Injects a constant value to a parsed Ruby script. This method is invoked during EvalUnit#run() is executed.
    • remove

      public void remove()
      Attempts to remove this constant from top self or receiver.