This commit is contained in:
Kyle Banker 2011-06-20 23:13:32 -04:00
parent 4f4e6ee833
commit 20d916bf98
1 changed files with 3 additions and 8 deletions

View File

@ -67,11 +67,10 @@ module BSON
end end
def keys def keys
@ordered_keys# || [] @ordered_keys.dup
end end
def []=(key, value) def []=(key, value)
#@ordered_keys ||= []
unless has_key?(key) unless has_key?(key)
@ordered_keys << key @ordered_keys << key
end end
@ -79,14 +78,12 @@ module BSON
end end
def each def each
#@ordered_keys ||= []
@ordered_keys.each { |k| yield k, self[k] } @ordered_keys.each { |k| yield k, self[k] }
self self
end end
alias :each_pair :each alias :each_pair :each
def to_a def to_a
#@ordered_keys ||= []
@ordered_keys.map { |k| [k, self[k]] } @ordered_keys.map { |k| [k, self[k]] }
end end
@ -95,7 +92,7 @@ module BSON
end end
def replace(other) def replace(other)
@ordered_keys = other.keys @ordered_keys.replace(other.keys)
super super
end end
@ -106,17 +103,15 @@ module BSON
end end
def merge!(other) def merge!(other)
#@ordered_keys ||= []
@ordered_keys += other.keys # unordered if not an BSON::OrderedHash @ordered_keys += other.keys # unordered if not an BSON::OrderedHash
@ordered_keys.uniq! @ordered_keys.uniq!
super(other) super(other)
end end
alias :update :merge! alias :update :merge!
def dup def dup
result = OrderedHash.new result = OrderedHash.new
#@ordered_keys ||= []
@ordered_keys.each do |key| @ordered_keys.each do |key|
result[key] = self[key] result[key] = self[key]
end end