Module: ObjectShadow::InstanceVariables
- Included in:
- ObjectShadow
- Defined in:
- lib/object_shadow/instance_variables.rb
Instance Method Summary collapse
-
#[](ivar_name) ⇒ Object
Returns the instance variable given Please note: Does not expect @ prefix.
-
#[]=(ivar_name, value) ⇒ Object
Sets the instance variable given Please note: Does not expect @ prefix.
- #remove(ivar_name) ⇒ Object
- #to_a ⇒ Object
- #to_h ⇒ Object
- #variable?(ivar_name) ⇒ Boolean
- #variables ⇒ Object
Instance Method Details
#[](ivar_name) ⇒ Object
Returns the instance variable given Please note: Does not expect @ prefix
7 8 9 |
# File 'lib/object_shadow/instance_variables.rb', line 7 def [](ivar_name) object.instance_variable_get(:"@#{ivar_name}") end |
#[]=(ivar_name, value) ⇒ Object
Sets the instance variable given Please note: Does not expect @ prefix
13 14 15 |
# File 'lib/object_shadow/instance_variables.rb', line 13 def []=(ivar_name, value) object.instance_variable_set(:"@#{ivar_name}", value) end |
#remove(ivar_name) ⇒ Object
17 18 19 |
# File 'lib/object_shadow/instance_variables.rb', line 17 def remove(ivar_name) object.remove_instance_variable(:"@#{ivar_name}") end |
#to_a ⇒ Object
33 34 35 |
# File 'lib/object_shadow/instance_variables.rb', line 33 def to_a variables.map{ |ivar| self[ivar] } end |
#to_h ⇒ Object
29 30 31 |
# File 'lib/object_shadow/instance_variables.rb', line 29 def to_h variables.map{ |ivar| [ivar, self[ivar]] }.to_h end |
#variable?(ivar_name) ⇒ Boolean
21 22 23 |
# File 'lib/object_shadow/instance_variables.rb', line 21 def variable?(ivar_name) object.instance_variable_defined?(:"@#{ivar_name}") end |
#variables ⇒ Object
25 26 27 |
# File 'lib/object_shadow/instance_variables.rb', line 25 def variables object.instance_variables.map{ |ivar| ivar[1..-1].to_sym } end |