diff options
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/hash_with_indifferent_access.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index 9dc93de5a9..f89704d906 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -153,6 +153,20 @@ module ActiveSupport def symbolize_keys; to_hash.symbolize_keys end def to_options!; self 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 + # Convert to a Hash with String keys. def to_hash Hash.new(default).merge!(self) |