Module: Undoable
- Defined in:
- lib/kyanite/general/undoable.rb
Overview
Undoable Module
Save and restore objects. Great for try-and-error-algorithms.
- Kyanite definitions
- Kyanite tests and examples
- Usage
-
require ‘kyanite/general/undoable’
Constant Summary collapse
- @@undoable_history =
Hash.new
Class Method Summary collapse
-
.clear ⇒ Object
Discards all saved states of all objects.
Instance Method Summary collapse
-
#load_and_delete ⇒ Object
Loads a saved state of an object, the saved state will be discarded.
-
#load_and_keep ⇒ Object
Loads a saved state of an object, the saved state remains in memory.
-
#save(method = :dup) ⇒ Object
Saves an object.
Class Method Details
.clear ⇒ Object
Discards all saved states of all objects.
39 40 41 |
# File 'lib/kyanite/general/undoable.rb', line 39 def self.clear @@undoable_history.clear end |
Instance Method Details
#load_and_delete ⇒ Object
Loads a saved state of an object, the saved state will be discarded.
32 33 34 |
# File 'lib/kyanite/general/undoable.rb', line 32 def load_and_delete @@undoable_history.delete(self.object_id) end |
#load_and_keep ⇒ Object
Loads a saved state of an object, the saved state remains in memory.
25 26 27 |
# File 'lib/kyanite/general/undoable.rb', line 25 def load_and_keep @@undoable_history[self.object_id] end |
#save(method = :dup) ⇒ Object
Saves an object.
17 18 19 20 |
# File 'lib/kyanite/general/undoable.rb', line 17 def save(method=:dup) return if self == @@undoable_history[self.object_id] # nichts zu tun @@undoable_history[self.object_id] = self.send(method) end |