Package org.jruby.embed.variable
Class LocalGlobalVariable
java.lang.Object
org.jruby.embed.variable.AbstractVariable
org.jruby.embed.variable.GlobalVariable
org.jruby.embed.variable.LocalGlobalVariable
- All Implemented Interfaces:
BiVariable
An implementation of BiVariable for JSR223 style global variable. The assigned
name is like a local variables in Java, but a global in Ruby.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jruby.embed.variable.BiVariable
BiVariable.Type -
Field Summary
FieldsFields inherited from class org.jruby.embed.variable.AbstractVariable
fromRuby, javaObject, javaType, name, receiver, rubyObject -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateLocalGlobalVariable(RubyObject receiver, String name, Object... javaObject) (package private)LocalGlobalVariable(RubyObject receiver, String name, IRubyObject irubyObject) A constructor used when local global type variables are retrieved from Ruby. -
Method Summary
Modifier and TypeMethodDescriptionstatic BiVariablegetInstance(RubyObject receiver, String name, Object... javaObject) Returns an instance of this class.getType()Returns enum type of this variable defined inBiVariable.voidinject()Injects a global value to a parsed Ruby script.static booleanisValidName(Object name) Returns true if the given name is a local global type variable.voidremove()Removes this object fromBiVariableMap.static voidretrieve(RubyObject receiver, BiVariableMap vars) Retrieves global variables eagerly from Ruby right after the evaluation.static voidretrieveByKey(Ruby runtime, BiVariableMap vars, String name) Retrieves a global variable by key from Ruby runtime after the evaluation.private static voidupdateLocalGlobal(RubyObject receiver, BiVariableMap vars, String name, IRubyObject value) Methods inherited from class org.jruby.embed.variable.GlobalVariable
isPredefined, isReceiverIdentical, retrieve, setJavaObject, tryEagerInjection, tryEagerInjectionMethods inherited from class org.jruby.embed.variable.AbstractVariable
getCurrentContext, getJavaObject, getName, getReceiver, getRubyClass, getRubyObject, getRuntime, getTopSelf, getTopSelf, isValidName, setRubyObject, updateByJavaObject, updateRubyObject
-
Field Details
-
VALID_NAME
- See Also:
-
-
Constructor Details
-
LocalGlobalVariable
-
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 nameirubyObject- Ruby global object
-
-
Method Details
-
getInstance
Returns an instance of this class. This factory method is used when a local global type variable is put intoBiVariableMap.- Parameters:
runtime- Ruby runtimename- a variable namejavaObject- Java object that should be assigned to.- Returns:
- the instance of LocalGlobalVariable
-
retrieve
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
Retrieves a global variable by key from Ruby runtime after the evaluation. This method is used when eager retrieval is off.- Parameters:
runtime- Ruby runtimevars- map to save a retrieved global variable.name- name of the global variable
-
getType
Returns enum type of this variable defined inBiVariable.- Specified by:
getTypein interfaceBiVariable- Overrides:
getTypein classGlobalVariable- Returns:
- this enum type, BiVariable.Type.GlobalVariable.
-
isValidName
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:
injectin interfaceBiVariable- Overrides:
injectin classGlobalVariable
-
remove
public void remove()Removes this object fromBiVariableMap.- Specified by:
removein interfaceBiVariable- Overrides:
removein classGlobalVariable- Parameters:
runtime- environment where a variable is removed.
-