Created
April 27, 2011 03:33
-
-
Save brianstorti/943672 to your computer and use it in GitHub Desktop.
Mixin to encapsulate functionality
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
module Summable | |
def sum | |
inject{ |i,j| i + j } | |
end | |
end | |
class Array | |
include Summable | |
end | |
puts [1,2,3,4,5].sum | |
class Range | |
include Summable | |
end | |
puts ('a'..'z').sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment