Class: RVM::Interpreter::VariableStorageCallback

Inherits:
VariableStorage show all
Defined in:
lib/rvm/environment.rb

Overview

The callback storang is used to help publishing variables from a ruby class to the rVM, it will get and set the variables during runtime.

It will link getter and setter methods and not the instance variable itself, which means also computed attributes can be handled by this.

This class is made if it is nessessary that a script always has access to constantly chaning data within a object and not only deal with static values set once.

Instance Method Summary collapse

Constructor Details

#initialize(obj, var, writable = true) ⇒ VariableStorageCallback

The construtor takes 3 parameters to specifie the object it shold be linked with, the attribute to handle and writable that will define if the VariableStorage can be written too by the script.

var is expected to by a Symbol equal the the function, the getter will call obj.var and the setter will call obj.var=.



235
236
237
238
239
240
# File 'lib/rvm/environment.rb', line 235

def initialize obj, var, writable = true
  super(nil, writable)
  @obj = obj
  @get = var.to_sym
  @set = "#{var}=".to_sym
end

Instance Method Details

#valObject

The getter will call the getter of the object to handle to get the current value.



251
252
253
# File 'lib/rvm/environment.rb', line 251

def val
  @obj.send(@get)
end

#val=(v) ⇒ Object

This methods sets the variable passed to the object by sending it to the setter method.



244
245
246
247
# File 'lib/rvm/environment.rb', line 244

def val= v
  @obj.send(@set,v) if @writable
  @obj.send(@get)
end