This project is archived and is in readonly mode.
#injecting on Enumerable
Reported by Adam Keys | September 3rd, 2008 @ 11:24 AM | in 2.x
injecting
makes inject
easier to use.
Rather than returning the accumulator from your block, the
accumulator is modified in place.
Apparently Merb had this method for a while, but lost it in the rewrite. I've adapted it to Rails in an idiomatic style.
For example:
%w(foo bar).injecting({}) { |hsh, str| hsh[str] = str.upcase } # => {'foo' => 'FOO', 'bar' => 'BAR'}
Comments and changes to this ticket
-
Michael Koziarski September 3rd, 2008 @ 01:03 PM
I like the functionality but we could make this a backport of the 1.9 feature each_with_object right?
http://redmine.ruby-lang.org/rep...
That'd involve changing the name and the order of arguments
-
Repository September 3rd, 2008 @ 03:23 PM
- State changed from new to committed
(from [10fe6a6d8940300dd6698ec38e9c9573404e687d]) Add each_with_object from 1.9 for a more convenient alternative to inject.
Signed-off-by: Michael Koziarski michael@koziarski.com [#962 state:committed] http://github.com/rails/rails/co...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 962 #injecting on Enumerable Signed-off-by: Michael Koziarski michael@koziarski.com [#...