Skip to content

Instantly share code, notes, and snippets.

@brianstorti
Created April 27, 2011 03:33
Show Gist options
  • Save brianstorti/943672 to your computer and use it in GitHub Desktop.
Save brianstorti/943672 to your computer and use it in GitHub Desktop.
Mixin to encapsulate functionality
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