Top Description Fields Constructors Methods
org.jruby.embed.variable

public Class GlobalVariable

extends AbstractVariable
Class Inheritance
Known Direct Subclasses
org.jruby.embed.variable.LocalGlobalVariable
Imports
java.util.Arrays, .HashSet, .Set, org.jruby.Ruby, .RubyObject, org.jruby.embed.internal.BiVariableMap, org.jruby.internal.runtime.GlobalVariables, org.jruby.runtime.builtin.IRubyObject

An implementation of BiVariable for a Ruby global variable.
Author
Yoko Harada <[email protected]>

Field Summary

Modifier and TypeField and Description
private static final Set<String>
private static final String[]
private static final String
Inherited from org.jruby.embed.variable.AbstractVariable:
fromRubyjavaObjectjavaTypenamereceiverrubyObject

Constructor Summary

AccessConstructor and Description
protected
GlobalVariable(RubyObject receiver, String name, Object... javaObjects)

pack-priv
GlobalVariable(RubyObject receiver, String
the global variable name
name
,
IRubyObject
Ruby global object
irubyObject
)

A constructor used when global variables are retrieved from Ruby.

Method Summary

Modifier and TypeMethod and Description
public static BiVariable

Returns:

the instance of GlobalVariable
getInstance
(RubyObject
Receiver object returned when a script is evaluated.
receiver
,
String
a variable name
name
,
Object...
Java object that should be assigned to.
javaObject
)

Returns an instance of this class.

public BiVariable.Type

Returns:

this enum type, BiVariable.Type.GlobalVariable.
getType
()

Implements org.jruby.embed.variable.BiVariable.getType.

Returns enum type of this variable defined in BiVariable.

public void
inject()

Implements org.jruby.embed.variable.BiVariable.inject.

A global variable is injected when it is set.

protected static boolean
isPredefined(final String name)

public boolean

Returns:

true always
isReceiverIdentical
(RubyObject recv)

Overrides org.jruby.embed.variable.AbstractVariable.isReceiverIdentical.

Implements org.jruby.embed.variable.BiVariable.isReceiverIdentical.

Returns true if a given receiver is identical to the receiver this object has.

public static boolean

Returns:

true if the given name is of a Ruby global variable.
isValidName
(Object
is a name to be checked.
name
)

Returns true if the given name is a decent Ruby global variable.

public void
remove()

Implements org.jruby.embed.variable.BiVariable.remove.

Attempts to remove this variable from top self or receiver.

public static void
retrieve(IRubyObject
receiver object returned when a script is evaluated.
receiver
,
BiVariableMap
map to save retrieved global variables.
vars
)

Retrieves global variables from Ruby after the evaluation.

public static void
retrieveByKey(Ruby
Ruby runtime
runtime
,
BiVariableMap
map to save a retrieved global variable.
vars
,
String
name of the global variable
key
)

Retrieves a global variable by key from Ruby after the evaluation.

public void
setJavaObject(Ruby
is used to convert a Java object to Ruby object.
runtime
,
Object
is a variable value to be set.
javaObject
)

Overrides org.jruby.embed.variable.AbstractVariable.setJavaObject.

Implements org.jruby.embed.variable.BiVariable.setJavaObject.

Sets a Java object and its Ruby type as a value of this object.

public void
tryEagerInjection(Ruby runtime, IRubyObject receiver)
Deprecated

public void
tryEagerInjection(final IRubyObject
is the instance that will have variable injection.
receiver
)

Injects a global variable value to a parsed Ruby script.

private static void
updateGlobalVar(final BiVariableMap vars, final RubyObject receiver, final String name, final IRubyObject value)

Inherited from org.jruby.embed.variable.AbstractVariable:
getCurrentContextgetJavaObjectgetNamegetReceivergetRubyClassgetRubyObjectgetRuntimegetTopSelfgetTopSelfisValidNamesetRubyObjectupdateByJavaObjectupdateRubyObject

Field Detail

PREDEFINED_NAMESback to summary
private static final Set<String> PREDEFINED_NAMES
PREDEFINED_PATTERNSback to summary
private static final String[] PREDEFINED_PATTERNS
VALID_NAMEback to summary
private static final String VALID_NAME

Constructor Detail

GlobalVariableback to summary
protected GlobalVariable(RubyObject receiver, String name, Object... javaObjects)
GlobalVariableback to summary
pack-priv GlobalVariable(RubyObject receiver, String name, IRubyObject irubyObject)

A constructor used when global variables are retrieved from Ruby.

Parameters
name:String

the global variable name

irubyObject:IRubyObject

Ruby global object

Method Detail

getInstanceback to summary
public static BiVariable getInstance(RubyObject receiver, String name, Object... javaObject)

Returns an instance of this class. This factory method is used when a global variable is put in BiVariableMap.

Parameters
receiver:RubyObject

Receiver object returned when a script is evaluated.

name:String

a variable name

javaObject:Object[]

Java object that should be assigned to.

Returns:BiVariable

the instance of GlobalVariable

getTypeback to summary
public BiVariable.Type getType()

Implements org.jruby.embed.variable.BiVariable.getType.

Returns enum type of this variable defined in BiVariable.

Returns:BiVariable.Type

this enum type, BiVariable.Type.GlobalVariable.

Annotations
@Override
injectback to summary
public void inject()

Implements org.jruby.embed.variable.BiVariable.inject.

A global variable is injected when it is set. This method does nothing. Instead injection is done by tryEagerInjection.

Annotations
@Override
isPredefinedback to summary
protected static boolean isPredefined(final String name)
isReceiverIdenticalback to summary
public boolean isReceiverIdentical(RubyObject recv)

Overrides org.jruby.embed.variable.AbstractVariable.isReceiverIdentical.

Implements org.jruby.embed.variable.BiVariable.isReceiverIdentical.

Returns true if a given receiver is identical to the receiver this object has.

Returns:boolean

true always

Annotations
@Override
isValidNameback to summary
public static boolean isValidName(Object name)

Returns true if the given name is a decent Ruby global variable. Unless returns false.

Parameters
name:Object

is a name to be checked.

Returns:boolean

true if the given name is of a Ruby global variable.

removeback to summary
public void remove()

Implements org.jruby.embed.variable.BiVariable.remove.

Attempts to remove this variable from top self or receiver.

Annotations
@Override
retrieveback to summary
public static void retrieve(IRubyObject receiver, BiVariableMap vars)

Retrieves global variables from Ruby after the evaluation.

Parameters
receiver:IRubyObject

receiver object returned when a script is evaluated.

vars:BiVariableMap

map to save retrieved global variables.

retrieveByKeyback to summary
public static void retrieveByKey(Ruby runtime, BiVariableMap vars, String key)

Retrieves a global variable by key from Ruby after the evaluation.

Parameters
runtime:Ruby

Ruby runtime

vars:BiVariableMap

map to save a retrieved global variable.

key:String

name of the global variable

setJavaObjectback to summary
public void setJavaObject(Ruby runtime, Object javaObject)

Overrides org.jruby.embed.variable.AbstractVariable.setJavaObject.

Implements org.jruby.embed.variable.BiVariable.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.

Parameters
runtime:Ruby

is used to convert a Java object to Ruby object.

javaObject:Object

is a variable value to be set.

Annotations
@Override
tryEagerInjectionback to summary
public void tryEagerInjection(Ruby runtime, IRubyObject receiver)

Deprecated

Annotations
@Deprecated
tryEagerInjectionback to summary
public void tryEagerInjection(final IRubyObject receiver)

Injects a global variable value to a parsed Ruby script. This method is invoked during EvalUnit#run() is executed.

Parameters
receiver:IRubyObject

is the instance that will have variable injection.

updateGlobalVarback to summary
private static void updateGlobalVar(final BiVariableMap vars, final RubyObject receiver, final String name, final IRubyObject value)