Class: DefaultInitArray

Inherits:
Array
  • Object
show all
Defined in:
lib/graphr/base_extensions.rb

Direct Known Subclasses

ArrayOfArrays, ArrayOfHashes

Instance Method Summary collapse

Methods inherited from Array

#delete_at_indices, #equality_uniq

Constructor Details

#initialize(*args, &initblock) ⇒ DefaultInitArray

Returns a new instance of DefaultInitArray.



16
17
18
19
# File 'lib/graphr/base_extensions.rb', line 16

def initialize(*args, &initblock)
  super(*args)
  @initblock = initblock
end

Instance Method Details

#[](index) ⇒ Object



21
22
23
# File 'lib/graphr/base_extensions.rb', line 21

def [](index)
  super(index) || (self[index] = @initblock.call(index))
end