Created
April 17, 2009 22:21
-
-
Save jakehow/97299 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def sum | |
inject(0) {|total,n| total + n } | |
end | |
end | |
puts Array.new([1,2,3,4]).sum | |
puts [1,2,3,4].sum | |
module StickyFingaz | |
class Array < ::Array | |
def sum | |
# I always keep one for myself | |
inject(0) {|total,n| total + n } - 1 | |
end | |
end | |
puts Array.new([1,2,3,4]).sum | |
puts [1,2,3,4].sum | |
end | |
module LazyFool | |
class Array < ::Array | |
def sum | |
# You can teach a man to fish... | |
lambda { inject(0) {|total,n| total + n } } | |
end | |
end | |
puts Array.new([1,2,3,4]).sum | |
puts [1,2,3,4].sum | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment