angry_hash 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +12 -0
- data/VERSION +1 -1
- data/angry_hash.gemspec +4 -3
- data/examples/normal_hash.eg.rb +11 -0
- data/lib/angry_hash.rb +16 -7
- metadata +4 -3
data/Changelog.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## 0.2.2
|
2
|
+
|
3
|
+
Changes:
|
4
|
+
- `#to_normal_hash` can now return a hash with symbol keys. The default is still to use string keys as is default within `AngryHash`.
|
5
|
+
|
6
|
+
## 0.2.1
|
7
|
+
|
8
|
+
Changes:
|
9
|
+
|
10
|
+
- In `#merge` & friends `other` hash is now converted to an AngryHash before conversion.
|
11
|
+
This ensures subhashes in `other` but not `this` end up as AngryHashes in `this` after merging.
|
12
|
+
|
1
13
|
## 0.2.0
|
2
14
|
|
3
15
|
Features:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/angry_hash.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{angry_hash}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Lachie Cox"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-30}
|
13
13
|
s.description = %q{A stabler mash with different emphases. Used in plus2 projects AngryMob and Igor.}
|
14
14
|
s.email = %q{lachie@plus2.com.au}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -41,7 +41,8 @@ Gem::Specification.new do |s|
|
|
41
41
|
"examples/dup_eg.rb",
|
42
42
|
"examples/eg_helper.rb",
|
43
43
|
"examples/extension_tracking.rb",
|
44
|
-
"examples/merge_eg.rb"
|
44
|
+
"examples/merge_eg.rb",
|
45
|
+
"examples/normal_hash.eg.rb"
|
45
46
|
]
|
46
47
|
|
47
48
|
if s.respond_to? :specification_version then
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'eg_helper'
|
2
|
+
|
3
|
+
eg 'to normal hash' do
|
4
|
+
ah = AngryHash[:a => 1, :b => {:c => :d}]
|
5
|
+
Assert( ah.to_normal_hash == {'a' => 1, 'b' => {'c' => :d}} )
|
6
|
+
end
|
7
|
+
|
8
|
+
eg 'to normal hash with symbol keys' do
|
9
|
+
ah = AngryHash[:a => 1, :b => {'c' => :d}]
|
10
|
+
Assert( ah.to_normal_hash(:symbols) == {:a => 1, :b => {:c => :d}} )
|
11
|
+
end
|
data/lib/angry_hash.rb
CHANGED
@@ -99,24 +99,33 @@ class AngryHash < Hash
|
|
99
99
|
self
|
100
100
|
end
|
101
101
|
|
102
|
-
def to_normal_hash
|
103
|
-
__to_hash(self)
|
102
|
+
def to_normal_hash(keys=nil)
|
103
|
+
__to_hash(self,keys)
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
|
+
def __to_hash(value,keys,cycle_guard={})
|
106
107
|
return cycle_guard[value.hash] if cycle_guard.key?(value.hash)
|
107
108
|
|
108
109
|
case value
|
109
110
|
when Hash
|
110
111
|
new_hash = cycle_guard[value.hash] = {}
|
111
112
|
|
112
|
-
|
113
|
-
|
114
|
-
|
113
|
+
if keys == :symbols
|
114
|
+
# TODO DRY
|
115
|
+
value.inject(new_hash) do |hash,(k,v)|
|
116
|
+
hash[k.to_sym] = __to_hash(v,keys,cycle_guard)
|
117
|
+
hash
|
118
|
+
end
|
119
|
+
else
|
120
|
+
value.inject(new_hash) do |hash,(k,v)|
|
121
|
+
hash[k] = __to_hash(v,keys,cycle_guard)
|
122
|
+
hash
|
123
|
+
end
|
115
124
|
end
|
116
125
|
when Array
|
117
126
|
new_array = cycle_guard[value.hash] = []
|
118
127
|
|
119
|
-
value.each {|v| new_array << __to_hash(v,cycle_guard)}
|
128
|
+
value.each {|v| new_array << __to_hash(v,keys,cycle_guard)}
|
120
129
|
else
|
121
130
|
value
|
122
131
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Lachie Cox
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-08-
|
17
|
+
date: 2010-08-30 00:00:00 +10:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -79,3 +79,4 @@ test_files:
|
|
79
79
|
- examples/eg_helper.rb
|
80
80
|
- examples/extension_tracking.rb
|
81
81
|
- examples/merge_eg.rb
|
82
|
+
- examples/normal_hash.eg.rb
|