diff options
author | lholden <lholden@yellowpages.com> | 2009-01-21 16:17:24 -0800 |
---|---|---|
committer | lholden <lholden@yellowpages.com> | 2009-01-21 16:17:24 -0800 |
commit | 19f8bb2808316dfca1f009538c3505ba144f614b (patch) | |
tree | 1ab9e925e83b988ed2a1858aa19236e2bcd79a60 /activesupport/lib/active_support/ordered_hash.rb | |
parent | b8fadd708b9850a77e1f64038763fffcff502499 (diff) | |
parent | 73cc5f270a5c2a2eab76c6c02615fec608822494 (diff) | |
download | rails-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.rb | 31 |
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)} |