Module: Enumerable
- Defined in:
- lib/enumerable.rb
Overview
TODO: Avoid monkey-patching.
Instance Method Summary collapse
Instance Method Details
#mean ⇒ Object
3 4 5 |
# File 'lib/enumerable.rb', line 3 def mean self.reduce(:+) / self.length.to_f end |
#standard_deviation ⇒ Object
12 13 14 |
# File 'lib/enumerable.rb', line 12 def standard_deviation Math.sqrt(self.variance) end |
#variance ⇒ Object
7 8 9 10 |
# File 'lib/enumerable.rb', line 7 def variance mean = self.mean self.reduce(0) { |memo, value| memo + ((value - mean) ** 2) } / (self.length - 1).to_f end |