Class InstanceVariable

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

public class InstanceVariable extends AbstractVariable
An implementation of BiVariable for a Ruby instance variable.
  • Field Details

  • Constructor Details

    • InstanceVariable

      private InstanceVariable(RubyObject receiver, String name, Object... javaObjects)
    • InstanceVariable

      public InstanceVariable(IRubyObject receiver, 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
    • InstanceVariable

      InstanceVariable(RubyObject receiver, String name, IRubyObject irubyObject)
  • Method Details

    • getInstance

      public static BiVariable getInstance(RubyObject receiver, String name, 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.
    • updateInstanceVar

      static void updateInstanceVar(RubyObject receiver, BiVariableMap vars)
    • retrieveByKey

      public static void retrieveByKey(RubyObject receiver, BiVariableMap vars, 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(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.