Permalink
Browse files

Added OrderedHash#delete [#113 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
1 parent a40223d commit d75525b045b9f27ed108912a6dbdbad5ab775045 @snostorm snostorm committed with josh May 5, 2008
Showing with 19 additions and 0 deletions.
  1. +6 −0 activesupport/lib/active_support/ordered_options.rb
  2. +13 −0 activesupport/test/ordered_options_test.rb
@@ -18,6 +18,12 @@ def [](key)
pair = assoc(key)
pair ? pair.last : nil
end
+
+ def delete(key)
+ pair = assoc(key)
+ pair ? array_index = index(pair) : nil
+ array_index ? delete_at(array_index).last : nil
+ end
def keys
collect { |key, value| key }
@@ -29,6 +29,19 @@ def test_assignment
assert_equal value, @ordered_hash.values.last
assert_equal value, @ordered_hash[key]
end
+
+ def test_delete
+ key, value = 'white', 'ffffff'
+ bad_key = 'black'
+
+ @ordered_hash[key] = value
+ assert_equal @keys.length + 1, @ordered_hash.length
+
+ assert_equal value, @ordered_hash.delete(key)
+ assert_equal @keys.length, @ordered_hash.length
+
+ assert_nil @ordered_hash.delete(bad_key)
+ end
end
class OrderedOptionsTest < Test::Unit::TestCase

0 comments on commit d75525b

Please sign in to comment.