Class: Array
- Defined in:
- lib/clevic/cache_table.rb,
lib/clevic/extensions.rb
Overview
This is part of Array in case the programmer wants to use a simple array instead of a CacheTable.
Direct Known Subclasses
Instance Method Summary collapse
-
#cached_at?(index) ⇒ Boolean
For use with CacheTable.
-
#group ⇒ Object
group by ascending values.
- #range ⇒ Object
- #search ⇒ Object
- #section ⇒ Object
- #sparse ⇒ Object
- #sparse_hash ⇒ Object
Instance Method Details
#cached_at?(index) ⇒ Boolean
For use with CacheTable. Return true if something is cached, false otherwise
173 174 175 |
# File 'lib/clevic/cache_table.rb', line 173 def cached_at?( index ) !at(index).nil? end |
#group ⇒ Object
group by ascending values
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/clevic/extensions.rb', line 74 def group parts = [] next_section = section if next_section.empty? parts else parts << section parts + self[section.size..-1].group end end |
#range ⇒ Object
85 86 87 |
# File 'lib/clevic/extensions.rb', line 85 def range first..last end |
#search ⇒ Object
177 178 179 |
# File 'lib/clevic/cache_table.rb', line 177 def search raise "not implemented" end |
#section ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/clevic/extensions.rb', line 63 def section return [] if empty? rv = [first] self[1..-1].each_with_index do |next_value, index| break if rv.last.succ != next_value rv << next_value end rv end |
#sparse ⇒ Object
57 58 59 60 61 |
# File 'lib/clevic/extensions.rb', line 57 def sparse (first..last).map do |index| index if include?( index ) end end |
#sparse_hash ⇒ Object
51 52 53 54 55 |
# File 'lib/clevic/extensions.rb', line 51 def sparse_hash Hash[ *(first..last).map do |index| [index, include?( index ) ] end.flatten ] end |