angry_hash 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/angry_hash.gemspec +2 -2
- data/examples/dup_eg.rb +20 -0
- data/lib/angry_hash.rb +23 -36
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
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.0.
|
8
|
+
s.version = "0.0.5"
|
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-
|
12
|
+
s.date = %q{2010-06-02}
|
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.files = [
|
data/examples/dup_eg.rb
CHANGED
@@ -66,3 +66,23 @@ eg 'duping copies symbols' do
|
|
66
66
|
Assert( ! ah2.database.isg_sandbox_v5.server.nil? )
|
67
67
|
Assert( ah2.database.isg_sandbox_v5.server == @original['database']['isg_sandbox_v5']['server'] )
|
68
68
|
end
|
69
|
+
|
70
|
+
module Extendo
|
71
|
+
def as_dag
|
72
|
+
dag = dup
|
73
|
+
dag
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
eg 'duping from ext' do
|
78
|
+
ah = AngryHash[ @original ]
|
79
|
+
ah.extend(Extendo)
|
80
|
+
|
81
|
+
ah2 = ah.as_dag
|
82
|
+
|
83
|
+
Show( AngryHash.shooper )
|
84
|
+
Show( ah.__id__ )
|
85
|
+
Show( ah2.__id__ )
|
86
|
+
|
87
|
+
Show( ah2 )
|
88
|
+
end
|
data/lib/angry_hash.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
class AngryHash < Hash
|
2
|
+
def self.shooper
|
3
|
+
"mooper"
|
4
|
+
end
|
2
5
|
|
3
6
|
def self.[](other)
|
4
7
|
super(__convert(other))
|
@@ -164,54 +167,38 @@ class AngryHash < Hash
|
|
164
167
|
|
165
168
|
|
166
169
|
# duplicating convert
|
167
|
-
def self.__convert(hash,cycle_watch=
|
170
|
+
def self.__convert(hash,cycle_watch=[])
|
168
171
|
new_hash = hash.inject(AngryHash.new) do |hash,(k,v)|
|
169
172
|
hash.regular_writer( __convert_key(k), __convert_value(v,cycle_watch) )
|
170
173
|
hash
|
171
174
|
end
|
172
175
|
|
173
|
-
#puts "re-extend? #{AngryHash === hash} #{hash.__extending_modules.inspect if (AngryHash === hash)}"
|
174
|
-
#if AngryHash === hash && hash.__extended?
|
175
|
-
#puts "rex"
|
176
|
-
#hash.__extending_modules.each {|mod| puts "rexmod=#{mod}"; new_hash.extend(mod)}
|
177
|
-
#end
|
178
|
-
|
179
176
|
new_hash
|
180
177
|
end
|
181
178
|
|
182
|
-
|
183
|
-
|
184
|
-
#end
|
185
|
-
#def __extended?
|
186
|
-
#!__extending_modules.empty?
|
187
|
-
#end
|
188
|
-
#def extend(mod)
|
189
|
-
#puts "extending with #{mod}"
|
190
|
-
#__extending_modules << mod
|
191
|
-
#puts "extending mods: #{__extending_modules.inspect}"
|
192
|
-
#super
|
193
|
-
#end
|
194
|
-
|
179
|
+
def self.__convert_value(v,cycle_watch=[])
|
180
|
+
id = v.__id__
|
195
181
|
|
182
|
+
return if cycle_watch.include? id
|
196
183
|
|
197
|
-
|
198
|
-
|
184
|
+
begin
|
185
|
+
cycle_watch << id
|
199
186
|
|
200
|
-
|
201
|
-
|
187
|
+
original_v = v
|
188
|
+
v = v.to_hash if v.respond_to?(:to_hash)
|
202
189
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
190
|
+
case v
|
191
|
+
when Hash
|
192
|
+
__convert(v,cycle_watch)
|
193
|
+
when Array
|
194
|
+
v.map {|vv| __convert_value(vv,cycle_watch)}
|
195
|
+
when Fixnum,Symbol,NilClass,TrueClass,FalseClass,Float
|
196
|
+
v
|
197
|
+
else
|
198
|
+
v.dup
|
199
|
+
end
|
200
|
+
ensure
|
201
|
+
cycle_watch.pop
|
215
202
|
end
|
216
203
|
end
|
217
204
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 5
|
9
|
+
version: 0.0.5
|
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-
|
17
|
+
date: 2010-06-02 00:00:00 +10:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|