Class: ThinModels::LazyArray::MemoizedLength
- Inherits:
-
ThinModels::LazyArray
- Object
- ThinModels::LazyArray
- ThinModels::LazyArray::MemoizedLength
- Defined in:
- lib/thin_models/lazy_array.rb
Overview
Memoizes the #length of the array, but does not at present memoize the results of each or slice_from_start_and_length.
#length will be memoized as a result of a direct call to #length (which uses an underlying #_length), or as a result of a full iteration via #each (which uses an underlying #_each)
Your extension points are now #_each, #_length and #slice_from_start_and_length
Direct Known Subclasses
Instance Method Summary collapse
Methods inherited from ThinModels::LazyArray
#[], #empty?, #first, #initialize, #join, #last, #map, #size, #slice_from_start_and_length, #to_json
Constructor Details
This class inherits a constructor from ThinModels::LazyArray
Instance Method Details
#_length ⇒ Object
152 |
# File 'lib/thin_models/lazy_array.rb', line 152 alias :_length :length |
#each ⇒ Object
145 146 147 148 149 150 |
# File 'lib/thin_models/lazy_array.rb', line 145 def each length = 0 _each {|item| yield item; length += 1} @length = length self end |
#inspect ⇒ Object
157 158 159 160 161 162 163 |
# File 'lib/thin_models/lazy_array.rb', line 157 def inspect if @length "[ThinModels::LazyArray(length=#{@length}):...]" else "[ThinModels::LazyArray:...]" end end |
#length ⇒ Object
153 154 155 |
# File 'lib/thin_models/lazy_array.rb', line 153 def length @length ||= _length end |