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 +4 -0
- data/lib/nested_hash.rb +9 -2
- data/lib/nested_hash/version.rb +1 -1
- data/test/test_simple_to_complex_hash.rb +7 -0
- metadata +4 -4
data/Changelog
CHANGED
data/lib/nested_hash.rb
CHANGED
@@ -27,12 +27,19 @@ class NestedHash < Hash
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def delete(key)
|
30
|
-
|
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
|
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|
|
data/lib/nested_hash/version.rb
CHANGED
@@ -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:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.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-
|
18
|
+
date: 2012-05-29 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|