org.jruby.embed.variable
Interface BiVariable

All Known Implementing Classes:
Argv, ClassVariable, Constant, GlobalVariable, InstanceVariable, LocalGlobalVariable, PersistentLocalVariable, TransientLocalVariable

public interface BiVariable

Represents bidirectional, both Java and Ruby, variables. Users don't instantiate BiVariable type objects. Instead, users can get this type object from BiVariableMap after a variable is set to the map. Users can set variables in Java program explicitly through put() methods in ScriptingContainer and BiVariableMap or equivalents. However, variables in Ruby scripts are set in the map implicitly. When variables and constants are used in the script, those are automatically saved in the map converting to this type.

Author:
Yoko Harada

Nested Class Summary
static class BiVariable.Type
          Defines a type correspond to Ruby's variables and constant types.
 
Method Summary
 java.lang.Object getJavaObject()
          Returns a value of the variable this object holds in Java type.
 java.lang.String getName()
          Returns a name of the variable this object holds.
 IRubyObject getReceiver()
          Returns the original receiver where this variable has been retrieved.
 IRubyObject getRubyObject()
          Returns a value of the variable this object holds in a org.jruby.runtime.builtin.IRubyObject type.
 BiVariable.Type getType()
          Returns one of the Ruby's variables or constant types defined by Type.
 void inject()
          Injects a variable value to a parsed Ruby script.
 boolean isReceiverIdentical(RubyObject receiver)
          Returns true if a given receiver is identical to the receiver this object has.
 void remove()
          Attempts to remove this variable/constant from top self or receiver.
 void setJavaObject(Ruby runtime, java.lang.Object javaObject)
          Sets a Java object 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.
 

Method Detail

getType

BiVariable.Type getType()
Returns one of the Ruby's variables or constant types defined by Type.

Returns:
a type that corresponds to Ruby's variables and constant types.

getReceiver

IRubyObject getReceiver()
Returns the original receiver where this variable has been retrieved.

Returns:
an original receiver.

isReceiverIdentical

boolean isReceiverIdentical(RubyObject receiver)
Returns true if a given receiver is identical to the receiver this object has.

Returns:
true if identical otherwise false.

getName

java.lang.String getName()
Returns a name of the variable this object holds. The name follows Ruby's naming rule.

Returns:
a name of the variable

getJavaObject

java.lang.Object getJavaObject()
Returns a value of the variable this object holds in Java type.

Returns:
a value in Java type.

setJavaObject

void setJavaObject(Ruby runtime,
                   java.lang.Object javaObject)
Sets a Java object as a value of this object. At the same time, an equivalent Ruby object is set automatically.

Parameters:
runtime - is used to convert a Java object to Ruby object.
javaObject - is a variable value to be set.

inject

void inject()
Injects a variable value to a parsed Ruby script. This method is invoked during EvalUnit#run() is executed. Users don't use this method.


getRubyObject

IRubyObject getRubyObject()
Returns a value of the variable this object holds in a org.jruby.runtime.builtin.IRubyObject type.

Returns:
a value in IRubyObject type.

setRubyObject

void setRubyObject(IRubyObject rubyObject)
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.

Parameters:
runtime - is environment where a variable injection occurs
rubyObject - is a variable value to be set.

remove

void remove()
Attempts to remove this variable/constant from top self or receiver.



Copyright © 2002-2009 JRuby Team. All Rights Reserved.