Class LocalGlobalVariable

java.lang.Object
org.jruby.embed.variable.GlobalVariable
org.jruby.embed.variable.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.
Author:
Yoko Harada <[email protected]>
  • Field Details

    • receiver

      protected final IRubyObject receiver
    • name

      protected final String name
    • javaObject

      protected volatile Object javaObject
    • javaType

      protected volatile Class javaType
    • rubyObject

      protected volatile IRubyObject rubyObject
    • fromRuby

      protected volatile boolean fromRuby
  • 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:
      receiver - Receiver object returned when a script is evaluated.
      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.
    • 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
    • updateByJavaObject

      protected void updateByJavaObject(Ruby runtime, Object... values)
    • updateRubyObject

      protected void updateRubyObject(IRubyObject rubyObject)
    • getReceiver

      public IRubyObject getReceiver()
      Description copied from interface: BiVariable
      Returns the original receiver where this variable has been retrieved.
      Specified by:
      getReceiver in interface BiVariable
      Returns:
      an original receiver.
    • getName

      public String getName()
      Description copied from interface: BiVariable
      Returns a name of the variable this object holds. The name follows Ruby's naming rule.
      Specified by:
      getName in interface BiVariable
      Returns:
      a name of the variable
    • getJavaObject

      public Object getJavaObject()
      Description copied from interface: BiVariable
      Returns a value of the variable this object holds in Java type.
      Specified by:
      getJavaObject in interface BiVariable
      Returns:
      a value in Java type.
    • getRubyObject

      public IRubyObject getRubyObject()
      Description copied from interface: BiVariable
      Returns a value of the variable this object holds in a org.jruby.runtime.builtin.IRubyObject type.
      Specified by:
      getRubyObject in interface BiVariable
      Returns:
      a value in IRubyObject type.
    • setRubyObject

      public void setRubyObject(IRubyObject rubyObject)
      Description copied from interface: BiVariable
      Sets a org.jruby.runtime.builtin.IRubyObject type, Ruby object as a value of this object. At the same time, an equivalent Java object is set automatically.
      Specified by:
      setRubyObject in interface BiVariable
      Parameters:
      rubyObject - is a variable value to be set.
    • getRubyClass

      protected static RubyModule getRubyClass(Ruby runtime)
    • isValidName

      protected static boolean isValidName(String pattern, Object name)