From 7394d12dc7c4bd6c1604e482042efab23f455794 Mon Sep 17 00:00:00 2001 From: Eloy Duran Date: Thu, 11 Dec 2008 14:12:06 +0100 Subject: 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 --- activesupport/lib/active_support/ordered_hash.rb | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'activesupport/lib') 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 -- cgit v1.2.3