From 816abecf90167c4df7d2117188bfa9d19b752696 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Sat, 23 Jul 2011 15:41:36 -0400 Subject: Insure that Enumerable#index_by, group_by, ... return Enumerators --- activesupport/lib/active_support/core_ext/enumerable.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'activesupport/lib/active_support/core_ext/enumerable.rb') 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" => , "David Heinemeier Hansson" => , ...} # def index_by + return to_enum :index_by unless block_given? Hash[map { |elem| [yield(elem), elem] }] end -- cgit v1.2.3