Skip to content

Instantly share code, notes, and snippets.

@rb2k
Created April 21, 2011 16:28
Show Gist options
  • Save rb2k/934921 to your computer and use it in GitHub Desktop.
Save rb2k/934921 to your computer and use it in GitHub Desktop.
sum and mean for the Array class
class Array
def sum
inject( nil ) { |sum,x| sum ? sum+x : x }
end
def mean
sum.to_f / size.to_f
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment