提交 bdfd11e6 编写于 作者: A Aaron Patterson

mutations on the underlying hash should also mutate the discard set

上级 dea16026
......@@ -93,7 +93,7 @@ def initialize_copy(other)
end
def []=(k, v) #:nodoc:
keep(k)
@discard.delete k
@flashes[k] = v
end
......@@ -102,7 +102,7 @@ def [](k)
end
def update(h) #:nodoc:
h.keys.each { |k| keep(k) }
@discard.subtract h.keys
@flashes.update h
self
end
......@@ -116,6 +116,7 @@ def key?(name)
end
def delete(key)
@discard.delete key
@flashes.delete key
self
end
......@@ -129,6 +130,7 @@ def empty?
end
def clear
@discard.clear
@flashes.clear
end
......@@ -139,7 +141,7 @@ def each(&block)
alias :merge! :update
def replace(h) #:nodoc:
@discard = Set.new
@discard.clear
@flashes.replace h
self
end
......
......@@ -104,6 +104,15 @@ def test_update_sweep
assert_equal({'hello' => 'world', 'hi' => 'mom'}, @hash.to_hash)
end
def test_update_delete_sweep
@hash['hello'] = 'world'
@hash.delete 'hello'
@hash.update({'hello' => 'mom'})
@hash.sweep
assert_equal({'hello' => 'mom'}, @hash.to_hash)
end
def test_delete_sweep
@hash['hello'] = 'world'
@hash['hi'] = 'mom'
......@@ -148,5 +157,15 @@ def test_keep_all_sweep
@hash.sweep
assert_equal({'omg' => 'world', 'hello' => 'world'}, @hash.to_hash)
end
def test_double_sweep
@hash['hello'] = 'world'
@hash.sweep
assert_equal({'hello' => 'world'}, @hash.to_hash)
@hash.sweep
assert_equal({}, @hash.to_hash)
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册