From e276ab0fa1640d001570eece17fa3185e294d806 Mon Sep 17 00:00:00 2001 From: James A. Rosen Date: Wed, 20 Oct 2010 08:01:02 -0700 Subject: [PATCH] OrderedHash#select now preserves order [#5843 state:resolved] --- activesupport/lib/active_support/ordered_hash.rb | 2 ++ activesupport/test/ordered_hash_test.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 0 deletions(-) diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb index 5445412..9d303eb 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -117,6 +117,8 @@ module ActiveSupport alias_method :each_pair, :each + alias_method :select, :find_all + def clear super @keys.clear diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index fc5e41e..04330f4 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -107,6 +107,14 @@ class OrderedHashTest < Test::Unit::TestCase assert_equal @keys, keys end + def test_find_all + assert_equal @keys, @ordered_hash.find_all { true }.map(&:first) + end + + def test_select + assert_equal @keys, @ordered_hash.select { true }.map(&:first) + end + def test_delete_if copy = @ordered_hash.dup copy.delete('pink') -- 1.7.1.1