Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/array_op_custom.rb

Instance Method Summary collapse

Instance Method Details

#*(other) ⇒ Object



14
15
16
17
18
# File 'lib/array_op_custom.rb', line 14

def *(other)
	self.each_index do |i|
		self[i] = other[i] ? self[i] * other[i] : self[i]
	end
end

#+(other) ⇒ Object



9
10
11
12
13
# File 'lib/array_op_custom.rb', line 9

def +(other)
	self.each_index do |i|
		self[i] = other[i] ? self[i] + other[i] : self[i]
	end
end

#-(other) ⇒ Object



19
20
21
22
23
# File 'lib/array_op_custom.rb', line 19

def -(other)
	self.each_index do |i|
		self[i] = other[i] ? (self[i] - other[i]).abs : self[i]
	end
end

#sumObject



37
38
39
# File 'lib/array_op_custom.rb', line 37

def sum
	self.reduce{|a, b| a + b}
end

#to_hObject



30
31
32
33
34
35
36
# File 'lib/array_op_custom.rb', line 30

def to_h
h = {}
self.each_with_index do |a, b|
	h[b.to_s.to_sym] = a
end
return h
end

#to_iObject



24
25
26
# File 'lib/array_op_custom.rb', line 24

def to_i
	self.map{|i| i.to_i}
end

#to_sObject



27
28
29
# File 'lib/array_op_custom.rb', line 27

def to_s
	self.map{|i| i.to_s}
end