Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

#injecting on Enumerable

#962

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'}

Reported by Adam Keys · September 3rd, 2008 @ 11:24 AM

State: committed
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Michael Koziarski
    Michael Koziarski

    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

    September 3rd, 2008 @ 01:03 PM

  2. Adam Keys
  3. Repository
    Repository
    • 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 #injecting on Enumerable state:committed] http://github.com/rails/rails/co...

    September 3rd, 2008 @ 03:23 PM