Method: ELFTools::LazyArray#initialize

Defined in:
lib/elftools/lazy_array.rb

#initialize(size) {|i| ... } ⇒ LazyArray

Instantiate a ELFTools::LazyArray object.

Examples:

arr = LazyArray.new(10) { |i| p "calc #{i}"; i * i }
p arr[2]
# "calc 2"
# 4

p arr[3]
# "calc 3"
# 9

p arr[3]
# 9

Parameters:

  • size (Integer)

    The size of array.

Yield Parameters:

  • i (Integer)

    Needs the i-th element.

Yield Returns:

  • (Object)

    Value of the i-th element.



30
31
32
33
# File 'lib/elftools/lazy_array.rb', line 30

def initialize(size, &block)
  super(Array.new(size))
  @block = block
end