Class: ThinModels::LazyArray::Memoized::Mapped
- Inherits:
-
ThinModels::LazyArray::Memoized
- Object
- ThinModels::LazyArray
- ThinModels::LazyArray::MemoizedLength
- ThinModels::LazyArray::Memoized
- ThinModels::LazyArray::Memoized::Mapped
- Defined in:
- lib/thin_models/lazy_array.rb
Overview
For when you want to map to a ThinModels::LazyArray which memoizes the results of the map
Instance Method Summary collapse
- #_each ⇒ Object
- #_length ⇒ Object
-
#initialize(underlying, &block) ⇒ Mapped
constructor
A new instance of Mapped.
- #slice_from_start_and_length(start, length) ⇒ Object
Methods inherited from ThinModels::LazyArray::Memoized
Methods inherited from ThinModels::LazyArray::MemoizedLength
Methods inherited from ThinModels::LazyArray
#[], #each, #empty?, #first, #inspect, #join, #last, #length, #map, #size, #to_json
Constructor Details
#initialize(underlying, &block) ⇒ Mapped
Returns a new instance of Mapped.
208 209 210 |
# File 'lib/thin_models/lazy_array.rb', line 208 def initialize(, &block) @underlying = ; @block = block end |
Instance Method Details
#_each ⇒ Object
212 213 214 |
# File 'lib/thin_models/lazy_array.rb', line 212 def _each @underlying.each {|x| yield @block.call(x)} end |
#_length ⇒ Object
216 217 218 |
# File 'lib/thin_models/lazy_array.rb', line 216 def _length @underlying.length end |
#slice_from_start_and_length(start, length) ⇒ Object
220 221 222 |
# File 'lib/thin_models/lazy_array.rb', line 220 def slice_from_start_and_length(start, length) @underlying.slice_from_start_and_length(start, length).map(&@block) end |