Class: BeanSprout::SparseArray
- Inherits:
-
Object
- Object
- BeanSprout::SparseArray
- Extended by:
- Forwardable
- Defined in:
- lib/bean_sprout/sparse_array.rb
Instance Method Summary collapse
- #fetch(index) ⇒ Object
- #fetch!(index) ⇒ Object
-
#initialize(index_offset = 0) ⇒ SparseArray
constructor
A new instance of SparseArray.
- #store ⇒ Object
Constructor Details
#initialize(index_offset = 0) ⇒ SparseArray
Returns a new instance of SparseArray.
9 10 11 12 |
# File 'lib/bean_sprout/sparse_array.rb', line 9 def initialize index_offset = 0 @entities = {} @index = index_offset end |
Instance Method Details
#fetch(index) ⇒ Object
19 20 21 |
# File 'lib/bean_sprout/sparse_array.rb', line 19 def fetch index @entities[index] end |
#fetch!(index) ⇒ Object
23 24 25 26 |
# File 'lib/bean_sprout/sparse_array.rb', line 23 def fetch! index raise "Unkown index #{index}." unless @entities.has_key? index fetch index end |
#store ⇒ Object
14 15 16 17 |
# File 'lib/bean_sprout/sparse_array.rb', line 14 def store index = next_index @entities[index] = yield index end |