Class: ELFTools::LazyArray
- Inherits:
-
Object
- Object
- ELFTools::LazyArray
- Defined in:
- lib/elftools/lazy_array.rb
Overview
A helper class for ELFTools easy to implement ‘lazy loading’ objects. Mainly used when loading sections, segments, and symbols.
Instance Method Summary collapse
-
#[](i) ⇒ Object
To access elements like a normal array.
-
#initialize(size) {|i| ... } ⇒ LazyArray
constructor
Instantiate a LazyArray object.
Constructor Details
#initialize(size) {|i| ... } ⇒ LazyArray
Instantiate a ELFTools::LazyArray object.
28 29 30 31 |
# File 'lib/elftools/lazy_array.rb', line 28 def initialize(size, &block) @internal = Array.new(size) @block = block end |
Instance Method Details
#[](i) ⇒ Object
To access elements like a normal array.
Elements are lazy loaded at the first time access it.
40 41 42 43 44 45 |
# File 'lib/elftools/lazy_array.rb', line 40 def [](i) # XXX: support negative index? return nil unless i.between?(0, @internal.size - 1) @internal[i] ||= @block.call(i) end |