Class: Factbase::LazyTaped::LazyTapedArray
- Inherits:
-
Object
- Object
- Factbase::LazyTaped::LazyTapedArray
- Defined in:
- lib/factbase/lazy_taped_array.rb
Overview
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.
16 17 18 19 20 21 |
# File 'lib/factbase/lazy_taped_array.rb', line 16 def initialize(origin, key, taped_hash, added) @origin = origin @key = key @taped_hash = taped_hash @added = added end |
Instance Method Details
#<<(item) ⇒ Object
40 41 42 43 44 |
# File 'lib/factbase/lazy_taped_array.rb', line 40 def <<(item) @taped_hash.ensure_copied_map @added.append(@taped_hash.tracking_id) @taped_hash.get_copied_array(@key) << item end |
#[](idx) ⇒ Object
28 29 30 |
# File 'lib/factbase/lazy_taped_array.rb', line 28 def [](idx) current_array[idx] end |
#any?(pattern = nil) ⇒ Boolean
36 37 38 |
# File 'lib/factbase/lazy_taped_array.rb', line 36 def any?(pattern = nil, &) pattern ? current_array.any?(pattern) : current_array.any?(&) end |
#each ⇒ Object
23 24 25 26 |
# File 'lib/factbase/lazy_taped_array.rb', line 23 def each(&) return to_enum(__method__) unless block_given? current_array.each(&) end |
#to_a ⇒ Object
32 33 34 |
# File 'lib/factbase/lazy_taped_array.rb', line 32 def to_a current_array.to_a end |
#uniq! ⇒ Object
46 47 48 49 50 |
# File 'lib/factbase/lazy_taped_array.rb', line 46 def uniq! @taped_hash.ensure_copied_map @added.append(@taped_hash.tracking_id) @taped_hash.get_copied_array(@key).uniq! end |