Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #14244 from arthurnn/orderd_hash_select_fix

Fix OrderedHash.select to return self instance.
  • Loading branch information...
commit 18c651659e4548661c385bd3c60a774ebd9bdaa2 2 parents 2af7a7b + a94966e
@spastorino spastorino authored
View
4 activesupport/lib/active_support/ordered_hash.rb
@@ -28,6 +28,10 @@ def encode_with(coder)
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
View
5 activesupport/test/ordered_hash_test.rb
@@ -120,7 +120,9 @@ def test_find_all
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 @@ def test_reject
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
Please sign in to comment.
Something went wrong with that request. Please try again.