diff options
author | Marc-Andre Lafortune <github@marc-andre.ca> | 2011-07-23 15:41:36 -0400 |
---|---|---|
committer | Marc-Andre Lafortune <github@marc-andre.ca> | 2011-07-23 15:52:37 -0400 |
commit | 816abecf90167c4df7d2117188bfa9d19b752696 (patch) | |
tree | f3bec0400b9a3282f8003af39245c1932c4cf085 /activesupport/lib | |
parent | c78503883902497521a710262a9ec005ca98ff74 (diff) | |
download | rails-816abecf90167c4df7d2117188bfa9d19b752696.tar.gz rails-816abecf90167c4df7d2117188bfa9d19b752696.tar.bz2 rails-816abecf90167c4df7d2117188bfa9d19b752696.zip |
Insure that Enumerable#index_by, group_by, ... return Enumerators
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/enumerable.rb | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index f67e7bf33e..f2dd34cc55 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -20,6 +20,7 @@ module Enumerable # "2006-02-24 -> Transcript, Transcript" # "2006-02-23 -> Transcript" def group_by + return to_enum :group_by unless block_given? assoc = ActiveSupport::OrderedHash.new each do |element| @@ -76,6 +77,7 @@ module Enumerable # (1..5).each_with_object(1) { |value, memo| memo *= value } # => 1 # def each_with_object(memo, &block) + return to_enum :each_with_object, memo unless block_given? each do |element| block.call(element, memo) end @@ -90,6 +92,7 @@ module Enumerable # => { "Chade- Fowlersburg-e" => <Person ...>, "David Heinemeier Hansson" => <Person ...>, ...} # def index_by + return to_enum :index_by unless block_given? Hash[map { |elem| [yield(elem), elem] }] end |