Class: AmberVM::Interpreter::VariableStorageCallback
- Inherits:
-
VariableStorage
- Object
- VariableStorage
- AmberVM::Interpreter::VariableStorageCallback
- Defined in:
- lib/amber/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
-
#initialize(obj, var, writable = true) ⇒ VariableStorageCallback
constructor
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. -
#val ⇒ Object
The getter will call the getter of the object to handle to get the current value.
-
#val=(v) ⇒ Object
This methods sets the variable passed to the object by sending it to the setter method.
Methods inherited from VariableStorage
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=.
230 231 232 233 234 235 |
# File 'lib/amber/environment.rb', line 230 def initialize obj, var, writable = true super(nil) @obj = obj @get = var.to_sym @set = "#{var}=".to_sym end |
Instance Method Details
#val ⇒ Object
The getter will call the getter of the object to handle to get the current value.
246 247 248 |
# File 'lib/amber/environment.rb', line 246 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.
239 240 241 242 |
# File 'lib/amber/environment.rb', line 239 def val= v @obj.send(@set,v) if @writable @obj.send(@get) end |