Class: Test::Rails::IvarProxy
Overview
A wrapper that allows instance variables to be manipulated using []
and []=
Instance Method Summary collapse
-
#[](ivar) ⇒ Object
Retrieves
ivar
from the wrapped object. -
#[]=(ivar, val) ⇒ Object
Sets
ivar
toval
on the wrapped object. -
#initialize(object) ⇒ IvarProxy
constructor
Wraps
object
allowing its instance variables to be manipulated.
Constructor Details
#initialize(object) ⇒ IvarProxy
Wraps object
allowing its instance variables to be manipulated.
12 13 14 |
# File 'lib/test/rails/ivar_proxy.rb', line 12 def initialize(object) @object = object end |
Instance Method Details
#[](ivar) ⇒ Object
Retrieves ivar
from the wrapped object.
19 20 21 |
# File 'lib/test/rails/ivar_proxy.rb', line 19 def [](ivar) @object.instance_variable_get "@#{ivar}" end |
#[]=(ivar, val) ⇒ Object
Sets ivar
to val
on the wrapped object.
26 27 28 |
# File 'lib/test/rails/ivar_proxy.rb', line 26 def []=(ivar, val) @object.instance_variable_set "@#{ivar}", val end |