aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/ordered_hash.rb
diff options
context:
space:
mode:
authorlholden <lholden@yellowpages.com>2009-01-21 16:17:24 -0800
committerlholden <lholden@yellowpages.com>2009-01-21 16:17:24 -0800
commit19f8bb2808316dfca1f009538c3505ba144f614b (patch)
tree1ab9e925e83b988ed2a1858aa19236e2bcd79a60 /activesupport/lib/active_support/ordered_hash.rb
parentb8fadd708b9850a77e1f64038763fffcff502499 (diff)
parent73cc5f270a5c2a2eab76c6c02615fec608822494 (diff)
downloadrails-19f8bb2808316dfca1f009538c3505ba144f614b.tar.gz
rails-19f8bb2808316dfca1f009538c3505ba144f614b.tar.bz2
rails-19f8bb2808316dfca1f009538c3505ba144f614b.zip
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'activesupport/lib/active_support/ordered_hash.rb')
-rw-r--r--activesupport/lib/active_support/ordered_hash.rb31
1 files changed, 22 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb
index 3def0be639..25ea505813 100644
--- a/activesupport/lib/active_support/ordered_hash.rb
+++ b/activesupport/lib/active_support/ordered_hash.rb
@@ -10,10 +10,14 @@ module ActiveSupport
@keys = []
end
+ def initialize_copy(other)
+ super
+ # make a deep copy of keys
+ @keys = other.keys
+ end
+
def []=(key, value)
- if !has_key?(key)
- @keys << key
- end
+ @keys << key if !has_key?(key)
super
end
@@ -24,6 +28,12 @@ module ActiveSupport
end
super
end
+
+ def delete_if
+ super
+ sync_keys!
+ self
+ end
def reject!
super
@@ -36,7 +46,7 @@ module ActiveSupport
end
def keys
- @keys
+ @keys.dup
end
def values
@@ -56,7 +66,7 @@ module ActiveSupport
end
def each
- keys.each {|key| yield [key, self[key]]}
+ @keys.each {|key| yield [key, self[key]]}
end
alias_method :each_pair, :each
@@ -73,13 +83,16 @@ module ActiveSupport
[k, v]
end
+ def merge!(other_hash)
+ other_hash.each {|k,v| self[k] = v }
+ self
+ end
+
def merge(other_hash)
- result = dup
- other_hash.each {|k,v| result[k]=v}
- result
+ dup.merge!(other_hash)
end
- private
+ private
def sync_keys!
@keys.delete_if {|k| !has_key?(k)}