Class: Factbase::LazyTaped::LazyTapedArray
- Inherits:
-
Object
- Object
- Factbase::LazyTaped::LazyTapedArray
- Defined in:
- lib/factbase/lazy_taped_array.rb
Overview
TODO:
#424:30min Add dedicated unit tests for LazyTapedArray class. Currently this class is tested indirectly through LazyTaped tests. We should add explicit tests for all public methods including each, [], to_a, any?, <<, and uniq! to ensure proper copy-on-write behavior.
Decorator of Array that triggers copy-on-write.
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #[](idx) ⇒ Object
- #any?(pattern = nil) ⇒ Boolean
- #each ⇒ Object
-
#initialize(origin, key, taped_hash, added) ⇒ LazyTapedArray
constructor
Creates a new lazy array wrapper.
- #to_a ⇒ Object
- #uniq! ⇒ Object
Constructor Details
#initialize(origin, key, taped_hash, added) ⇒ LazyTapedArray
Creates a new lazy array wrapper.
20 21 22 23 24 25 |
# File 'lib/factbase/lazy_taped_array.rb', line 20 def initialize(origin, key, taped_hash, added) @origin = origin @key = key @taped_hash = taped_hash @added = added end |
Instance Method Details
#<<(item) ⇒ Object
44 45 46 47 48 |
# File 'lib/factbase/lazy_taped_array.rb', line 44 def <<(item) @taped_hash.ensure_copied_map @added.append(@taped_hash.tracking_id) @taped_hash.get_copied_array(@key) << item end |
#[](idx) ⇒ Object
32 33 34 |
# File 'lib/factbase/lazy_taped_array.rb', line 32 def [](idx) current_array[idx] end |
#any?(pattern = nil) ⇒ Boolean
40 41 42 |
# File 'lib/factbase/lazy_taped_array.rb', line 40 def any?(pattern = nil, &) pattern ? current_array.any?(pattern) : current_array.any?(&) end |
#each ⇒ Object
27 28 29 30 |
# File 'lib/factbase/lazy_taped_array.rb', line 27 def each(&) return to_enum(__method__) unless block_given? current_array.each(&) end |
#to_a ⇒ Object
36 37 38 |
# File 'lib/factbase/lazy_taped_array.rb', line 36 def to_a current_array.to_a end |
#uniq! ⇒ Object
50 51 52 53 54 |
# File 'lib/factbase/lazy_taped_array.rb', line 50 def uniq! @taped_hash.ensure_copied_map @added.append(@taped_hash.tracking_id) @taped_hash.get_copied_array(@key).uniq! end |