Module: Immutability
- Included in:
- WithMemory
- Defined in:
- lib/immutability.rb,
lib/immutability/object.rb,
lib/immutability/with_memory.rb
Overview
Makes the object immutable (deeply frozen) with possibility to remember and forget previous states (snapshots).
Uses ‘ice_nine’ to freeze object deeply by the initializer
Defined Under Namespace
Modules: ClassMethods, WithMemory Classes: Object
Class Method Summary collapse
-
.with_memory ⇒ Module
Returns the module extended by features to record history.
Instance Method Summary collapse
-
#update(&block) ⇒ Object
Returns the new immutable instances that preserves old variables and updates some of them from inside the block.
Class Method Details
.with_memory ⇒ Module
Returns the module extended by features to record history
109 110 111 |
# File 'lib/immutability.rb', line 109 def self.with_memory WithMemory end |
Instance Method Details
#update(&block) ⇒ Object
Returns the new immutable instances that preserves old variables and updates some of them from inside the block
101 102 103 |
# File 'lib/immutability.rb', line 101 def update(&block) IceNine.deep_freeze dup.tap { |obj| obj.instance_eval(&block) if block } end |