Class: Mutability::Mutable
- Inherits:
-
Object
- Object
- Mutability::Mutable
- Extended by:
- Forwardable
- Defined in:
- lib/mutability/mutable.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#self ⇒ Object
Returns the value of attribute self.
Instance Method Summary collapse
- #freeze! ⇒ Object
-
#initialize(original) ⇒ Mutable
constructor
A new instance of Mutable.
- #revert! ⇒ Object
Constructor Details
#initialize(original) ⇒ Mutable
Returns a new instance of Mutable.
28 29 30 31 |
# File 'lib/mutability/mutable.rb', line 28 def initialize(original) @original = original.freeze # don't modify, even accidentally! revert! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object (private)
cheap delegation
44 45 46 |
# File 'lib/mutability/mutable.rb', line 44 def method_missing(sym, *args, &block) @self.send(sym, *args, &block) end |
Instance Attribute Details
#original ⇒ Object (readonly)
Returns the value of attribute original.
25 26 27 |
# File 'lib/mutability/mutable.rb', line 25 def original @original end |
#self ⇒ Object
Returns the value of attribute self.
26 27 28 |
# File 'lib/mutability/mutable.rb', line 26 def self @self end |
Instance Method Details
#freeze! ⇒ Object
33 34 35 |
# File 'lib/mutability/mutable.rb', line 33 def freeze! @original = @self.dup.freeze end |
#revert! ⇒ Object
37 38 39 |
# File 'lib/mutability/mutable.rb', line 37 def revert! @self = @original.dup # we want an unfrozen copy, so cannot clone end |