aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/ordered_hash.rb
diff options
context:
space:
mode:
authorEloy Duran <eloy.de.enige@gmail.com>2008-12-11 14:12:06 +0100
committerMichael Koziarski <michael@koziarski.com>2008-12-11 14:32:20 +0100
commit7394d12dc7c4bd6c1604e482042efab23f455794 (patch)
treee548b62a726ca7e5316538d2a47fd5bb7517c003 /activesupport/lib/active_support/ordered_hash.rb
parent69387ce0169b95d3a170cfb1c66a7570b1746e37 (diff)
downloadrails-7394d12dc7c4bd6c1604e482042efab23f455794.tar.gz
rails-7394d12dc7c4bd6c1604e482042efab23f455794.tar.bz2
rails-7394d12dc7c4bd6c1604e482042efab23f455794.zip
Fixed ActiveSupport::OrderedHash #delete_if, #reject!, and #reject, which did not sync the @keys after the operation.
This probably holds true for other mutating methods as well. Signed-off-by: Michael Koziarski <michael@koziarski.com>
Diffstat (limited to 'activesupport/lib/active_support/ordered_hash.rb')
-rw-r--r--activesupport/lib/active_support/ordered_hash.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb
index 1ed7737017..fa68db5604 100644
--- a/activesupport/lib/active_support/ordered_hash.rb
+++ b/activesupport/lib/active_support/ordered_hash.rb
@@ -25,6 +25,25 @@ module ActiveSupport
super
end
+ def delete_if
+ super
+ sync_keys!
+ self
+ end
+
+ def reject!
+ super
+ sync_keys!
+ self
+ end
+
+ def reject(&block)
+ dup.reject!(&block)
+ end
+
+ alias_method :super_keys, :keys
+ private :super_keys
+
def keys
@keys
end
@@ -48,6 +67,12 @@ module ActiveSupport
def each
keys.each {|key| yield [key, self[key]]}
end
+
+ private
+
+ def sync_keys!
+ (@keys - super_keys).each { |k| @keys.delete(k) }
+ end
end
end
end