diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-04-20 19:16:48 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-04-20 19:56:01 -0700 |
commit | 0b21ac5118c293b43e5370d7a3da980514f089a2 (patch) | |
tree | 5ad45c29bfaeddf83e39478748177e2056ebf0cb /activesupport | |
parent | 549c81db4a9ca941ea65ae2edafb0f34784f12f2 (diff) | |
download | rails-0b21ac5118c293b43e5370d7a3da980514f089a2.tar.gz rails-0b21ac5118c293b43e5370d7a3da980514f089a2.tar.bz2 rails-0b21ac5118c293b43e5370d7a3da980514f089a2.zip |
Ruby 1.8.7 compat: override unordered Enumerable#group_by
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/enumerable.rb | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index 1b96eb166a..8f111e29fc 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -1,4 +1,7 @@ module Enumerable + # Ruby 1.8.7 introduces group_by, but the result isn't ordered. Override it. + remove_method(:group_by) if [].respond_to?(:group_by) && RUBY_VERSION < '1.9' + # Collect an enumerable into sets, grouped by the result of a block. Useful, # for example, for grouping records by date. # @@ -19,7 +22,7 @@ module Enumerable (grouped[yield(element)] ||= []) << element grouped end - end if RUBY_VERSION < '1.9' + end unless [].respond_to?(:group_by) # Calculates a sum from the elements. Examples: # |