diff options
author | Arthur Neves <arthurnn@gmail.com> | 2014-02-26 15:22:52 -0500 |
---|---|---|
committer | Arthur Neves <arthurnn@gmail.com> | 2014-03-07 12:30:20 -0500 |
commit | a94966ea094fcfd94cf09642d3a561af80c64602 (patch) | |
tree | b0bd592c6dcc628c92d7c33e979cbaa401806746 /activesupport | |
parent | f60b5249194d71a5a7ad152332400af39543628f (diff) | |
download | rails-a94966ea094fcfd94cf09642d3a561af80c64602.tar.gz rails-a94966ea094fcfd94cf09642d3a561af80c64602.tar.bz2 rails-a94966ea094fcfd94cf09642d3a561af80c64602.zip |
Fix OrderedHash.select to return self instance.
On ruby 2.1.1 the behavior of .select and .reject has changed.
They will return a Hash new instance, so we need to override them to
keep the instance object class.
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/ordered_hash.rb | 4 | ||||
-rw-r--r-- | activesupport/test/ordered_hash_test.rb | 5 |
2 files changed, 8 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb index 58a2ce2105..4680d5acb7 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -28,6 +28,10 @@ module ActiveSupport coder.represent_seq '!omap', map { |k,v| { k => v } } end + def select(*args, &block) + dup.tap { |hash| hash.select!(*args, &block) } + end + def reject(*args, &block) dup.tap { |hash| hash.reject!(*args, &block) } end diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index 0b54026c64..460a61613e 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -120,7 +120,9 @@ class OrderedHashTest < ActiveSupport::TestCase end def test_select - assert_equal @keys, @ordered_hash.select { true }.map(&:first) + new_ordered_hash = @ordered_hash.select { true } + assert_equal @keys, new_ordered_hash.map(&:first) + assert_instance_of ActiveSupport::OrderedHash, new_ordered_hash end def test_delete_if @@ -143,6 +145,7 @@ class OrderedHashTest < ActiveSupport::TestCase assert_equal copy, @ordered_hash assert !new_ordered_hash.keys.include?('pink') assert @ordered_hash.keys.include?('pink') + assert_instance_of ActiveSupport::OrderedHash, new_ordered_hash end def test_clear |