2 # A wrapper that allows instance variables to be manipulated using +[]+ and
8 class IvarProxy #:nodoc:
11 # Wraps +object+ allowing its instance variables to be manipulated.
13 def initialize(object)
18 # Retrieves +ivar+ from the wrapped object.
21 get_variable "@#{ivar}"
25 # Sets +ivar+ to +val+ on the wrapped object.
28 set_variable "@#{ivar}", val
32 @object.instance_variables.each do |variable_full_name|
33 variable_name = variable_full_name[1...variable_full_name.length]
34 yield variable_name, get_variable(variable_full_name)
40 if @object.instance_variables.include?(var_name)
41 @object.send(:remove_instance_variable, var_name)
48 @object.instance_variables.include?("@#{key}")
52 def get_variable(name)
53 @object.instance_variable_get name
56 def set_variable(name, value)
57 @object.instance_variable_set name, value