aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/ordered_hash.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/ordered_hash.rb')
-rw-r--r--activesupport/lib/active_support/ordered_hash.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb
index b0d4f2bd86..e81bd013b6 100644
--- a/activesupport/lib/active_support/ordered_hash.rb
+++ b/activesupport/lib/active_support/ordered_hash.rb
@@ -52,6 +52,20 @@ module ActiveSupport
true
end
+ if RUBY_VERSION > '2.1.0'
+ # On Ruby 2.1.1 and later the behavior of .select and reject changed to
+ # return a new Hash instance so we need to override them to return an
+ # instance of the correct class.
+
+ def select(*args, &block)
+ dup.tap { |hash| hash.select!(*args, &block) }
+ end
+
+ def reject(*args, &block)
+ dup.tap { |hash| hash.reject!(*args, &block) }
+ end
+ end
+
# Hash is ordered in Ruby 1.9!
if RUBY_VERSION < '1.9'