Method: Heist::Runtime::Vector#initialize

Defined in:
lib/runtime/data/vector.rb

#initialize(*args, &block) ⇒ Vector

A Vector is initialized using a sequence of values, just like a Ruby Array. Optionally, it can be initialized using an array and a block, which will be used to map the array to new values before inserting into the Vector.

Vector.new([1,2,3,4]) { |x| x*x }
#=> #(1 2 3 4)


36
37
38
39
# File 'lib/runtime/data/vector.rb', line 36

def initialize(*args, &block)
  return super(*args) unless block_given?
  args.first.each_with_index { |cell, i| self[i] = block.call(cell) }
end