Package org.jruby.embed.variable
Class GlobalVariable
java.lang.Object
org.jruby.embed.variable.GlobalVariable
- All Implemented Interfaces:
BiVariable
- Direct Known Subclasses:
LocalGlobalVariable
An implementation of BiVariable for a Ruby global variable.
- Author:
- Yoko Harada <[email protected]>
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jruby.embed.variable.BiVariable
BiVariable.Type
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
protected Object
protected Class
protected final String
protected final IRubyObject
protected IRubyObject
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
GlobalVariable
(RubyObject receiver, String name, Object... javaObjects) -
Method Summary
Modifier and TypeMethodDescriptionstatic BiVariable
getInstance
(RubyObject receiver, String name, Object... javaObject) Returns an instance of this class.Returns a value of the variable this object holds in Java type.getName()
Returns a name of the variable this object holds.Returns the original receiver where this variable has been retrieved.protected static RubyModule
getRubyClass
(Ruby runtime) Returns a value of the variable this object holds in a org.jruby.runtime.builtin.IRubyObject type.getType()
Returns enum type of this variable defined inBiVariable
.void
inject()
A global variable is injected when it is set.protected static boolean
isPredefined
(String name) boolean
Returns true if a given receiver is identical to the receiver this object has.static boolean
isValidName
(Object name) Returns true if the given name is a decent Ruby global variable.protected static boolean
isValidName
(String pattern, Object name) void
remove()
Attempts to remove this variable from top self or receiver.static void
retrieve
(IRubyObject receiver, BiVariableMap vars) Retrieves global variables from Ruby after the evaluation.static void
retrieveByKey
(Ruby runtime, BiVariableMap vars, String key) Retrieves a global variable by key from Ruby after the evaluation.void
setJavaObject
(Ruby runtime, Object javaObject) Sets a Java object and its Ruby type as a value of this object.void
setRubyObject
(IRubyObject rubyObject) Sets a org.jruby.runtime.builtin.IRubyObject type, Ruby object as a value of this object.void
tryEagerInjection
(Ruby runtime, IRubyObject receiver) Deprecated.void
tryEagerInjection
(IRubyObject receiver) Injects a global variable value to a parsed Ruby script.protected void
updateByJavaObject
(Ruby runtime, Object... values) protected void
updateRubyObject
(IRubyObject rubyObject)
-
Field Details
-
receiver
-
name
-
javaObject
-
javaType
-
rubyObject
-
fromRuby
protected volatile boolean fromRuby
-
-
Constructor Details
-
GlobalVariable
-
-
Method Details
-
getInstance
Returns an instance of this class. This factory method is used when a global variable is put inBiVariableMap
.- Parameters:
receiver
- Receiver object returned when a script is evaluated.name
- a variable namejavaObject
- Java object that should be assigned to.- Returns:
- the instance of GlobalVariable
-
retrieve
Retrieves global variables from Ruby after the evaluation.- Parameters:
receiver
- receiver object returned when a script is evaluated.vars
- map to save retrieved global variables.
-
retrieveByKey
Retrieves a global variable by key from Ruby after the evaluation.- Parameters:
runtime
- Ruby runtimevars
- map to save a retrieved global variable.key
- name of the global variable
-
isPredefined
-
getType
Returns enum type of this variable defined inBiVariable
.- Returns:
- this enum type, BiVariable.Type.GlobalVariable.
-
isValidName
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
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 interfaceBiVariable
- 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. -
tryEagerInjection
Injects a global variable value to a parsed Ruby script. This method is invoked during EvalUnit#run() is executed.- Parameters:
receiver
- is the instance that will have variable injection.
-
remove
public void remove()Attempts to remove this variable from top self or receiver. -
isReceiverIdentical
Returns true if a given receiver is identical to the receiver this object has.- Specified by:
isReceiverIdentical
in interfaceBiVariable
- Returns:
- true always
-
updateByJavaObject
-
updateRubyObject
-
getReceiver
Description copied from interface:BiVariable
Returns the original receiver where this variable has been retrieved.- Specified by:
getReceiver
in interfaceBiVariable
- Returns:
- an original receiver.
-
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 interfaceBiVariable
- Returns:
- a name of the variable
-
getJavaObject
Description copied from interface:BiVariable
Returns a value of the variable this object holds in Java type.- Specified by:
getJavaObject
in interfaceBiVariable
- Returns:
- a value in Java type.
-
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 interfaceBiVariable
- Returns:
- a value in IRubyObject type.
-
setRubyObject
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 interfaceBiVariable
- Parameters:
rubyObject
- is a variable value to be set.
-
getRubyClass
-
isValidName
-