Class: Wee::State::Snapshot
Instance Method Summary collapse
- #add_ivar(ivar, value) ⇒ Object
-
#initialize(object) ⇒ Snapshot
constructor
A new instance of Snapshot.
- #restore ⇒ Object
- #take ⇒ Object
Constructor Details
#initialize(object) ⇒ Snapshot
Returns a new instance of Snapshot.
13 14 15 16 17 18 |
# File 'lib/wee/state.rb', line 13 def initialize(object) @object = object @snapshot = nil @has_snapshot = false @ivars = nil end |
Instance Method Details
#add_ivar(ivar, value) ⇒ Object
25 26 27 28 |
# File 'lib/wee/state.rb', line 25 def add_ivar(ivar, value) @ivars ||= {} @ivars[ivar] = value end |
#restore ⇒ Object
30 31 32 33 |
# File 'lib/wee/state.rb', line 30 def restore @object.restore_snapshot(@snapshot) if @has_snapshot @ivars.each_pair {|k,v| @object.instance_variable_set(k, v) } if @ivars end |
#take ⇒ Object
20 21 22 23 |
# File 'lib/wee/state.rb', line 20 def take @snapshot = @object.take_snapshot unless @has_snapshot @has_snapshot = true end |