Skip to content

Instantly share code, notes, and snippets.

@gjnoonan
Created June 4, 2010 08:30
Show Gist options
  • Save gjnoonan/425155 to your computer and use it in GitHub Desktop.
Save gjnoonan/425155 to your computer and use it in GitHub Desktop.
class Array
def sum
inject(0.0) { |result, el| result + el }
end
def mean
sum / size
end
end
[ 1,2,3,4,5,6,7,8,9,10 ].mean #=> 5.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment