This is written a bit better and more readable:

class Stddev
  def initialize(arr)
    @arr = arr
    @size = @arr.to_a.size
  end

  def sumofx
    @arr.inject {|a,b| a + b }
  end

  def sumofxsquared
    @arr.inject {|a,b| a + b**2}
  end

  def calculate
    Math.sqrt((sumofxsquared-((sumofx * sumofx)/@size))/(@size-1).to_f)
  end
end

a = [1,2,3,4,5]

Stddev.new(a).calculate


-- 
Posted via http://www.ruby-forum.com/.