org.jruby.embed.variable
Class InstanceVariable

java.lang.Object
  extended by org.jruby.embed.variable.InstanceVariable
All Implemented Interfaces:
BiVariable

public class InstanceVariable
extends java.lang.Object

An implementation of BiVariable for a Ruby instance variable.

Author:
Yoko Harada

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jruby.embed.variable.BiVariable
BiVariable.Type
 
Field Summary
protected  boolean fromRuby
           
protected  IRubyObject irubyObject
           
protected  java.lang.Object javaObject
           
protected  java.lang.Class javaType
           
protected  java.lang.String name
           
protected  IRubyObject receiver
           
 
Constructor Summary
InstanceVariable(IRubyObject receiver, java.lang.String name, IRubyObject irubyObject)
          A constructor used when instance variables are retrieved from Ruby.
 
Method Summary
static BiVariable getInstance(RubyObject receiver, java.lang.String name, java.lang.Object... javaObject)
          Returns an instance of this class.
 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.
protected  RubyModule getRubyClass(Ruby runtime)
           
 IRubyObject getRubyObject()
          Returns a value of the variable this object holds in a org.jruby.runtime.builtin.IRubyObject type.
 BiVariable.Type getType()
          Returns enum type of this variable defined in BiVariable.
 void inject()
          Injects an instance variable value to a parsed Ruby script.
 boolean isReceiverIdentical(RubyObject recv)
          Returns true if a given receiver is identical to the receiver this object has.
static boolean isValidName(java.lang.Object name)
          Returns true if the given name is a decent Ruby instance variable.
protected static boolean isValidName(java.lang.String pattern, java.lang.Object name)
           
 void remove()
          Attempts to remove this variable from top self or receiver.
static void retrieve(RubyObject receiver, BiVariableMap vars)
          Retrieves instance variables from Ruby after the evaluation.
static void retrieveByKey(RubyObject receiver, BiVariableMap vars, java.lang.String key)
          Retrieves a instance variable by key from Ruby runtime after the evaluation.
 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.
protected  void updateByJavaObject(Ruby runtime, java.lang.Object... values)
           
protected  void updateRubyObject(IRubyObject rubyObject)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

receiver

protected final IRubyObject receiver

name

protected java.lang.String name

javaObject

protected java.lang.Object javaObject

javaType

protected java.lang.Class javaType

irubyObject

protected IRubyObject irubyObject

fromRuby

protected boolean fromRuby
Constructor Detail

InstanceVariable

public InstanceVariable(IRubyObject receiver,
                        java.lang.String name,
                        IRubyObject irubyObject)
A constructor used when instance variables 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 instance variable name
irubyObject - Ruby instance object
Method Detail

getInstance

public static BiVariable getInstance(RubyObject receiver,
                                     java.lang.String name,
                                     java.lang.Object... javaObject)
Returns an instance of this class. This factory method is used when an instance variable is put in BiVariableMap.

Parameters:
runtime - Ruby runtime
name - a variable name
javaObject - Java object that should be assigned to.
Returns:
the instance of InstanceVariable

retrieve

public static void retrieve(RubyObject receiver,
                            BiVariableMap vars)
Retrieves instance variables from Ruby after the evaluation.

Parameters:
runtime - Ruby runtime
receiver - receiver object returned when a script is evaluated.
vars - map to save retrieved instance variables.

retrieveByKey

public static void retrieveByKey(RubyObject receiver,
                                 BiVariableMap vars,
                                 java.lang.String key)
Retrieves a instance variable 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

public BiVariable.Type getType()
Returns enum type of this variable defined in BiVariable.

Returns:
this enum type, BiVariable.Type.InstanceVariable.

isValidName

public static boolean isValidName(java.lang.Object name)
Returns true if the given name is a decent Ruby instance variable. Unless returns false.

Parameters:
name - is a name to be checked.
Returns:
true if the given name is of a Ruby instance variable.

inject

public void inject()
Injects an instance variable value to a parsed Ruby script. This method is invoked during EvalUnit#run() is executed.

Parameters:
runtime - is environment where a variable injection occurs
receiver - is the instance that will have variable injection.

remove

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


updateByJavaObject

protected void updateByJavaObject(Ruby runtime,
                                  java.lang.Object... values)

updateRubyObject

protected void updateRubyObject(IRubyObject rubyObject)

getReceiver

public IRubyObject getReceiver()
Description copied from interface: BiVariable
Returns the original receiver where this variable has been retrieved.

Specified by:
getReceiver in interface BiVariable
Returns:
an original receiver.

isReceiverIdentical

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

Specified by:
isReceiverIdentical in interface BiVariable
Returns:
true if identical otherwise false

getName

public java.lang.String 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 interface BiVariable
Returns:
a name of the variable

getJavaObject

public java.lang.Object getJavaObject()
Description copied from interface: BiVariable
Returns a value of the variable this object holds in Java type.

Specified by:
getJavaObject in interface BiVariable
Returns:
a value in Java type.

setJavaObject

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

Specified by:
setJavaObject in interface BiVariable
Parameters:
runtime - is used to convert a Java object to Ruby object.
javaObject - is a variable value to be set.

getRubyObject

public IRubyObject 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 interface BiVariable
Returns:
a value in IRubyObject type.

setRubyObject

public void setRubyObject(IRubyObject rubyObject)
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 interface BiVariable
Parameters:
rubyObject - is a variable value to be set.

getRubyClass

protected RubyModule getRubyClass(Ruby runtime)

isValidName

protected static boolean isValidName(java.lang.String pattern,
                                     java.lang.Object name)


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