Class LocalGlobalVariable

All Implemented Interfaces:
BiVariable

public class LocalGlobalVariable extends GlobalVariable
An implementation of BiVariable for JSR223 style global variable. The assigned name is like a local variables in Java, but a global in Ruby.
  • Field Details

  • Constructor Details

    • LocalGlobalVariable

      private LocalGlobalVariable(RubyObject receiver, String name, Object... javaObject)
    • LocalGlobalVariable

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

      public static void retrieve(RubyObject receiver, BiVariableMap vars)
      Retrieves global variables eagerly from Ruby right after the evaluation. The variable names to be retrieved must be in a variable map.
      Parameters:
      receiver - receiver object returned when a script is evaluated.
      vars - map to save retrieved global variables.
    • updateLocalGlobal

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

      public static void retrieveByKey(Ruby runtime, BiVariableMap vars, String name)
      Retrieves a global variable by key from Ruby runtime after the evaluation. This method is used when eager retrieval is off.
      Parameters:
      runtime - Ruby runtime
      vars - map to save a retrieved global variable.
      name - name of the global variable
    • getType

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

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

      public void inject()
      Injects a global value to a parsed Ruby script. This method is invoked during EvalUnit#run() is executed.
      Specified by:
      inject in interface BiVariable
      Overrides:
      inject in class GlobalVariable
    • remove

      public void remove()
      Removes this object from BiVariableMap.
      Specified by:
      remove in interface BiVariable
      Overrides:
      remove in class GlobalVariable
      Parameters:
      runtime - environment where a variable is removed.