Created
July 15, 2009 18:21
-
-
Save arya/147878 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
# inject but doesn't need you to return the memo, uses the same object. Doesn't work with immutable (i.e. summing) | |
module Enumerable | |
def inject_into(obj) | |
each {|e| yield(obj, e)} | |
obj | |
end | |
end | |
a = [1,2,3].inject_into([]) do |m, e| | |
m << (e + 1) | |
end | |
puts a.inspect # => [2,3,4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment