Skip to content

Instantly share code, notes, and snippets.

@nanodeath
Created January 4, 2009 07:03
Show Gist options
  • Save nanodeath/43018 to your computer and use it in GitHub Desktop.
Save nanodeath/43018 to your computer and use it in GitHub Desktop.
class Array
def sum
inject {|sum, n| sum + (n || 0)} || 0
end
# Sum two numeric arrays
def add(other_array)
raise ArgumentError unless other_array.is_a? Array
(length > other_array.length ? zip(other_array) : other_array.zip(self)).collect(&:sum)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment