Class: Fortitude::Support::InstanceVariableSet
- Inherits:
-
Object
- Object
- Fortitude::Support::InstanceVariableSet
- Defined in:
- lib/fortitude/support/instance_variable_set.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #each ⇒ Object
-
#initialize(target_object) ⇒ InstanceVariableSet
constructor
A new instance of InstanceVariableSet.
- #keys ⇒ Object
- #with_instance_variable_copying(widget) ⇒ Object
Constructor Details
#initialize(target_object) ⇒ InstanceVariableSet
Returns a new instance of InstanceVariableSet.
4 5 6 |
# File 'lib/fortitude/support/instance_variable_set.rb', line 4 def initialize(target_object) @target_object = target_object end |
Instance Method Details
#[](name) ⇒ Object
8 9 10 |
# File 'lib/fortitude/support/instance_variable_set.rb', line 8 def [](name) target_object.instance_variable_get("@#{name}") end |
#[]=(name, value) ⇒ Object
12 13 14 |
# File 'lib/fortitude/support/instance_variable_set.rb', line 12 def []=(name, value) target_object.instance_variable_set("@#{name}", value) end |
#each ⇒ Object
22 23 24 |
# File 'lib/fortitude/support/instance_variable_set.rb', line 22 def each keys.each { |k| yield k, self[k] } end |
#keys ⇒ Object
16 17 18 19 20 |
# File 'lib/fortitude/support/instance_variable_set.rb', line 16 def keys target_object.instance_variables.map do |instance_variable_name| $1.to_sym if instance_variable_name.to_s =~ /^@(.*)$/ end.compact end |
#with_instance_variable_copying(widget) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fortitude/support/instance_variable_set.rb', line 26 def () before_copy = .instance_variables skip_copy = before_copy - target_object.instance_variables () begin yield ensure (, skip_copy) end end |