Class GlobalVariable

java.lang.Object
org.jruby.embed.variable.AbstractVariable
org.jruby.embed.variable.GlobalVariable
All Implemented Interfaces:
BiVariable
Direct Known Subclasses:
LocalGlobalVariable

public class GlobalVariable extends AbstractVariable
An implementation of BiVariable for a Ruby global variable.
  • Field Details

    • VALID_NAME

      private static final String VALID_NAME
      See Also:
    • PREDEFINED_PATTERNS

      private static final String[] PREDEFINED_PATTERNS
    • PREDEFINED_NAMES

      private static final Set<String> PREDEFINED_NAMES
  • Constructor Details

    • GlobalVariable

      protected GlobalVariable(RubyObject receiver, String name, Object... javaObjects)
    • GlobalVariable

      GlobalVariable(RubyObject receiver, String name, IRubyObject irubyObject)
      A constructor used when global variables are retrieved from Ruby.
      Parameters:
      name - the global variable name
      irubyObject - Ruby global 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 global variable is put in BiVariableMap.
      Parameters:
      runtime - Ruby runtime
      name - a variable name
      javaObject - Java object that should be assigned to.
      Returns:
      the instance of GlobalVariable
    • retrieve

      public static void retrieve(IRubyObject receiver, BiVariableMap vars)
      Retrieves global variables from Ruby after the evaluation.
      Parameters:
      runtime - Ruby runtime
      receiver - receiver object returned when a script is evaluated.
      vars - map to save retrieved global variables.
    • updateGlobalVar

      private static void updateGlobalVar(BiVariableMap vars, RubyObject receiver, String name, IRubyObject value)
    • retrieveByKey

      public static void retrieveByKey(Ruby runtime, BiVariableMap vars, String key)
      Retrieves a global variable by key from Ruby after the evaluation.
      Parameters:
      runtime - Ruby runtime
      receiver - receiver object returned when a script is evaluated.
      vars - map to save a retrieved global variable.
      key - name of the global variable
    • isPredefined

      protected static boolean isPredefined(String name)
    • getType

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

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

      public void setJavaObject(Ruby runtime, Object javaObject)
      Sets a Java object and its Ruby type as a value of this object. At the same time, sets Ruby object to Ruby runtime.
      Specified by:
      setJavaObject in interface BiVariable
      Overrides:
      setJavaObject in class AbstractVariable
      Parameters:
      runtime - is used to convert a Java object to Ruby object.
      javaObject - is a variable value to be set.
    • inject

      public void inject()
      A global variable is injected when it is set. This method does nothing. Instead injection is done by tryEagerInjection.
    • tryEagerInjection

      @Deprecated public void tryEagerInjection(Ruby runtime, IRubyObject receiver)
      Deprecated.
    • tryEagerInjection

      public void tryEagerInjection(IRubyObject receiver)
      Injects a global variable value to a parsed Ruby script. This method is invoked during EvalUnit#run() is executed.
      Parameters:
      runtime - is environment where a variable injection occurs
      receiver - is the instance that will have variable injection.
    • remove

      public void remove()
      Attempts to remove this variable from top self or receiver.
    • isReceiverIdentical

      public boolean isReceiverIdentical(RubyObject recv)
      Returns true if a given receiver is identical to the receiver this object has.
      Specified by:
      isReceiverIdentical in interface BiVariable
      Overrides:
      isReceiverIdentical in class AbstractVariable
      Returns:
      true always