Module: Enumerable

Defined in:
lib/ctodo.rb

Instance Method Summary collapse

Instance Method Details

#avgObject



35
36
37
# File 'lib/ctodo.rb', line 35

def avg
	(length == 0) ? 0 : (sum * 1.0 / length)
end

#medianObject



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

def median
	sorted = self.sort
	sorted[self.length/2]
end

#sumObject



31
32
33
# File 'lib/ctodo.rb', line 31

def sum
	self.inject(0) { |sum,v| sum + v }
end