class Array
Public Instance Methods
*(other)
click to toggle source
# File lib/array_op_custom.rb, line 20 def *(other) if self.length >= other.length self.each_index do |i| self[i] = other[i] ? self[i] * other[i] : self[i] end elsif other.length > self.length other.each_index do |i| other[i] = self[i] ? self[i] * other[i] : other[i] end end end
+(other)
click to toggle source
# File lib/array_op_custom.rb, line 9 def +(other) if self.length >= other.length self.each_index do |i| self[i] = other[i] ? self[i] + other[i] : self[i] end elsif other.length > self.length other.each_index do |i| other[i] = self[i] ? self[i] + other[i] : other[i] end end end
-(other)
click to toggle source
# File lib/array_op_custom.rb, line 31 def -(other) if self.length >= other.length self.each_index do |i| self[i] = other[i] ? (self[i] - other[i]).abs : self[i] end elsif other.length > self.length other.each_index do |i| other[i] = self[i] ? (self[i] - other[i]).abs : other[i] end end end
==(other)
click to toggle source
# File lib/array_op_custom.rb, line 42 def ==(other) return self.dup.push(other) end
to_h()
click to toggle source
# File lib/array_op_custom.rb, line 51 def to_h h = {} self.each_with_index do |a, b| h[b.to_s.to_sym] = a end return h end
to_i()
click to toggle source
# File lib/array_op_custom.rb, line 45 def to_i self.map{|i| i.to_i} end
to_s()
click to toggle source
# File lib/array_op_custom.rb, line 48 def to_s self.map{|i| i.to_s} end