Method: Rust::MathArray#+

Defined in:
lib/rust/core/types/utils.rb

#+(other) ⇒ Object

Raises:

  • (ArgumentError)


85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/rust/core/types/utils.rb', line 85

def +(other)
    raise ArgumentError, "Expected array or numeric" if !other.is_a?(::Array) && !other.is_a?(Numeric)
    raise ArgumentError, "The two arrays must have the same size" if other.is_a?(::Array) && self.size != other.size
    
    result = self.clone
    other = [other] * self.size if other.is_a?(Numeric)
    for i in 0...self.size
        result[i] += other[i]
    end
    
    return result
end