aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-12-21 11:26:19 -0800
committerJosé Valim <jose.valim@gmail.com>2011-12-21 11:26:19 -0800
commitfccc952ccd9ac05f26ebb3419999d7aa3e70e83d (patch)
tree32dcebe278d61cdf4ca71cfae7612487eba59990 /railties/guides
parent1a358e43d204ef86229418e76c55579220b41207 (diff)
parentf1b4cacbae71585be3f5dcb4c1bdd7c78ef3d590 (diff)
downloadrails-fccc952ccd9ac05f26ebb3419999d7aa3e70e83d.tar.gz
rails-fccc952ccd9ac05f26ebb3419999d7aa3e70e83d.tar.bz2
rails-fccc952ccd9ac05f26ebb3419999d7aa3e70e83d.zip
Merge pull request #4104 from lest/remove-1-8-code
remove Enumerable#each_with_object from core_ext as it is present in ruby 1.9
Diffstat (limited to 'railties/guides')
-rw-r--r--railties/guides/source/active_support_core_extensions.textile26
1 files changed, 0 insertions, 26 deletions
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index cf9185a324..25d8f50a7b 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -1987,32 +1987,6 @@ people.pluck(:name) # => [ "David Heinemeier Hansson", "Jamie Heinemeier Hansson
NOTE: Defined in +active_support/core_ext/enumerable.rb+.
-h4. +each_with_object+
-
-The +inject+ method offers iteration with an accumulator:
-
-<ruby>
-[2, 3, 4].inject(1) {|product, i| product*i } # => 24
-</ruby>
-
-The block is expected to return the value for the accumulator in the next iteration, and this makes building mutable objects a bit cumbersome:
-
-<ruby>
-[1, 2].inject({}) {|h, i| h[i] = i**2; h} # => {1 => 1, 2 => 4}
-</ruby>
-
-See that spurious "+; h+"?
-
-Active Support backports +each_with_object+ from Ruby 1.9, which addresses that use case. It iterates over the collection, passes the accumulator, and returns the accumulator when done. You normally modify the accumulator in place. The example above would be written this way:
-
-<ruby>
-[1, 2].each_with_object({}) {|i, h| h[i] = i**2} # => {1 => 1, 2 => 4}
-</ruby>
-
-WARNING. Note that the item of the collection and the accumulator come in different order in +inject+ and +each_with_object+.
-
-NOTE: Defined in +active_support/core_ext/enumerable.rb+.
-
h4. +index_by+
The method +index_by+ generates a hash with the elements of an enumerable indexed by some key.