Package org.jruby.embed.variable
Class Constant
java.lang.Object
org.jruby.embed.variable.AbstractVariable
org.jruby.embed.variable.Constant
- All Implemented Interfaces:
BiVariable
An implementation of BiVariable for a Ruby constant.
-
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
ConstructorsModifierConstructorDescriptionprivateConstant(RubyObject receiver, String name, Object... javaObjects) (package private)Constant(RubyObject receiver, String name, IRubyObject irubyObject) A constructor used when constants 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 constant value to a parsed Ruby script.static booleanisValidName(Object name) Returns true if the given name is a decent Ruby constant.voidremove()Attempts to remove this constant from top self or receiver.static voidretrieve(RubyObject receiver, BiVariableMap vars) Retrieves constants from Ruby after the evaluation or method invocation.static voidretrieveByKey(RubyObject receiver, BiVariableMap vars, String key) Retrieves a constant by key from Ruby runtime after the evaluation.private static voidupdateConstants(RubyObject receiver, BiVariableMap vars) private static voidupdateConstantsOfSuperClass(RubyObject receiver, BiVariableMap vars) Methods inherited from class org.jruby.embed.variable.AbstractVariable
getCurrentContext, getJavaObject, getName, getReceiver, getRubyClass, getRubyObject, getRuntime, getTopSelf, getTopSelf, isReceiverIdentical, isValidName, setJavaObject, setRubyObject, updateByJavaObject, updateRubyObject
-
Field Details
-
VALID_NAME
- See Also:
-
-
Constructor Details
-
Constant
-
Constant
Constant(RubyObject receiver, String name, IRubyObject irubyObject) A constructor used when constants are retrieved from Ruby.- Parameters:
receiver- a receiver object that this variable/constant is originally in. When the variable/constant is originated from Ruby, receiver may not be null.name- the constant nameirubyObject- Ruby constant object
-
-
Method Details
-
getInstance
Returns an instance of this class. This factory method is used when a constant is put inBiVariableMap.- Parameters:
receiver- object that this constant/variable is in.name- a variable namejavaObject- Java object that should be assigned to.- Returns:
- the instance of Constant
-
retrieve
Retrieves constants from Ruby after the evaluation or method invocation.- Parameters:
receiver- receiver object returned when a script is evaluated.vars- map to save retrieved constants.
-
updateConstantsOfSuperClass
-
updateConstants
-
retrieveByKey
Retrieves a constant by key from Ruby runtime after the evaluation. This method is used when eager retrieval is off.- Parameters:
receiver- receiver object returned when a script is evaluated.vars- map to save retrieved instance variables.key- instace varible name
-
getType
Returns enum type of this variable defined inBiVariable.- Returns:
- this enum type, BiVariable.Type.Constant.
-
isValidName
Returns true if the given name is a decent Ruby constant. Unless returns false.- Parameters:
name- is a name to be checked.- Returns:
- true if the given name is of a Ruby constant.
-
inject
public void inject()Injects a constant value to a parsed Ruby script. This method is invoked during EvalUnit#run() is executed. -
remove
public void remove()Attempts to remove this constant from top self or receiver.
-