Class: ThinModels::LazyArray::Memoized::Mapped

Inherits:
ThinModels::LazyArray::Memoized show all
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

Methods inherited from ThinModels::LazyArray::Memoized

#[], #each, #inspect, #to_a

Methods inherited from ThinModels::LazyArray::MemoizedLength

#each, #inspect, #length

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(underlying, &block)
  @underlying = underlying; @block = block
end

Instance Method Details

#_eachObject



212
213
214
# File 'lib/thin_models/lazy_array.rb', line 212

def _each
  @underlying.each {|x| yield @block.call(x)}
end

#_lengthObject



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