Class: Immutability::Object Private
- Inherits:
-
Object
- Object
- Immutability::Object
- Includes:
- Enumerable
- Defined in:
- lib/immutability/object.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Describes the continuous object as a sequence of immutable snapshots with an option of searching the past state of the object
Instance Method Summary collapse
-
#at(point) ⇒ Object?
private
Returns the state of the object at some point in the past.
-
#each ⇒ Enumerator
private
Iterates via object’s snapshots from the current state to the past.
-
#initialize(current) ⇒ Object
constructor
private
Initializes the object from the current state (snapshot).
-
#version ⇒ Integer
private
The current (last) version of the object.
Constructor Details
#initialize(current) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the object from the current state (snapshot)
19 20 21 |
# File 'lib/immutability/object.rb', line 19 def initialize(current) @current = current end |
Instance Method Details
#at(point) ⇒ Object?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the state of the object at some point in the past
55 56 57 58 59 60 61 |
# File 'lib/immutability/object.rb', line 55 def at(point) ipoint = point.to_i target = (ipoint < 0) ? (version + ipoint) : ipoint return unless (0..version).include? target detect { |state| target.equal? state.version } end |
#each ⇒ Enumerator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Iterates via object’s snapshots from the current state to the past
37 38 39 40 41 42 43 44 |
# File 'lib/immutability/object.rb', line 37 def each return to_enum unless block_given? state = @current while state yield(state) state = state.parent end end |
#version ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The current (last) version of the object
The object knows nothing about its future
29 30 31 |
# File 'lib/immutability/object.rb', line 29 def version @current.version end |