nested_hash 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog CHANGED
@@ -1,3 +1,7 @@
1
+ 2012-05-29 Guillermo Alvarez <guillermo@cientifico.net>
2
+
3
+ * nested_hash.rb (delete): Allow delete to work with top level keys
4
+
1
5
  2012-05-25 Guillermo Alvarez <guillermo@cientifico.net>
2
6
 
3
7
  * nested_hash.rb (get/set): Implement get and set methods.
data/lib/nested_hash.rb CHANGED
@@ -27,12 +27,19 @@ class NestedHash < Hash
27
27
  end
28
28
 
29
29
  def delete(key)
30
- look_for(key,nil, :delete)
30
+ if split_key(key).size > 1
31
+ look_for(key,nil, :delete)
32
+ else
33
+ super(key)
34
+ end
31
35
  end
32
36
 
37
+ def split_key(key)
38
+ key.split(".")
39
+ end
33
40
 
34
41
  def look_for(key,value, op = :set)
35
- keys = key.split(".").map{|k| sanitize_key(k)}
42
+ keys = split_key(key).map{|k| sanitize_key(k)}
36
43
 
37
44
  previous = keys.shift
38
45
  top = (keys.inject(self) do |memo,key|
@@ -1,3 +1,3 @@
1
1
  class NestedHash < Hash
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -61,4 +61,11 @@ class NestedHashTest < Test::Unit::TestCase
61
61
  nh.compact_arrays!
62
62
  assert_equal({"person"=>[{}]}, nh)
63
63
  end
64
+
65
+ def test_delete_method2
66
+ nh = NestedHash.new()
67
+ nh.set("name" ,"guillermo")
68
+ nh.delete("name")
69
+ assert_equal({}, nh)
70
+ end
64
71
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nested_hash
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Guillermo A\xCC\x81lvarez"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-25 00:00:00 +00:00
18
+ date: 2012-05-29 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies: []
21
21