Method: Daru::Vector#set_at

Defined in:
lib/daru/vector.rb

#set_at(positions, val) ⇒ Object

Change value at given positions

Examples:

dv = Daru::Vector.new 'a'..'e'
dv.set_at [0, 1], 'x'
dv
# => #<Daru::Vector(5)>
#   0   x
#   1   x
#   2   c
#   3   d
#   4   e

Parameters:

  • positions (Array<object>)

    positional values

  • val (object)

    value to assign



290
291
292
293
294
# File 'lib/daru/vector.rb', line 290

def set_at positions, val
  validate_positions(*positions)
  positions.map { |pos| @data[pos] = val }
  update_position_cache
end