angry_hash 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/angry_hash.gemspec +41 -0
- data/examples/creation_eg.rb +38 -0
- data/examples/eg_helper.rb +6 -0
- data/lib/angry_hash.rb +25 -0
- metadata +6 -3
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/angry_hash.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{angry_hash}
|
8
|
+
s.version = "0.0.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Lachie Cox"]
|
12
|
+
s.date = %q{2010-04-29}
|
13
|
+
s.description = %q{A stabler mash with different emphases. Used in plus2 projects AngryMob and Igor.}
|
14
|
+
s.email = %q{lachie@plus2.com.au}
|
15
|
+
s.files = [
|
16
|
+
".gitignore",
|
17
|
+
"Rakefile",
|
18
|
+
"VERSION",
|
19
|
+
"angry_hash.gemspec",
|
20
|
+
"examples/creation_eg.rb",
|
21
|
+
"examples/eg_helper.rb",
|
22
|
+
"lib/angry_hash.rb",
|
23
|
+
"lib/angry_hash/merge_string.rb"
|
24
|
+
]
|
25
|
+
s.homepage = %q{http://github.com/plus2/angry_hash}
|
26
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
27
|
+
s.require_paths = ["lib"]
|
28
|
+
s.rubygems_version = %q{1.3.6}
|
29
|
+
s.summary = %q{A stabler mash with different emphases.}
|
30
|
+
|
31
|
+
if s.respond_to? :specification_version then
|
32
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
33
|
+
s.specification_version = 3
|
34
|
+
|
35
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
36
|
+
else
|
37
|
+
end
|
38
|
+
else
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'eg_helper'
|
2
|
+
|
3
|
+
eg.helpers do
|
4
|
+
def oids(v)
|
5
|
+
sub = case v
|
6
|
+
when Hash
|
7
|
+
hh = {}
|
8
|
+
v.each {|kk,vv| hh[kk] = oids(vv)}
|
9
|
+
hh
|
10
|
+
when Array
|
11
|
+
v.map {|vv| oids(vv)}
|
12
|
+
else
|
13
|
+
v
|
14
|
+
end
|
15
|
+
|
16
|
+
n = {:class => v.class, :oid => v.__id__, :sub => sub}
|
17
|
+
if v.respond_to?(:__id__)
|
18
|
+
n[:oid] = v.__id__
|
19
|
+
else
|
20
|
+
n[:oid] = 0
|
21
|
+
end
|
22
|
+
n
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
eg 'creation duplicates' do
|
27
|
+
a1 = AngryHash[ :a => { :b => 1 }, :c => [ 1, :d, {:e => :f}, nil, true, false, 1.0, [ 'x', 'y' ] ] ]
|
28
|
+
a2 = AngryHash[ a1 ]
|
29
|
+
|
30
|
+
pp oids(a1)
|
31
|
+
pp oids(a2)
|
32
|
+
|
33
|
+
Check(a1.c[2].__id__ != a2.c[2].__id__).is(true)
|
34
|
+
Check(a1.c[7].__id__ != a2.c[7].__id__).is(true)
|
35
|
+
end
|
36
|
+
|
37
|
+
eg 'cycle detection' do
|
38
|
+
end
|
data/lib/angry_hash.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
class AngryHash < Hash
|
2
|
+
|
2
3
|
def self.[](other)
|
3
4
|
super(__convert(other))
|
4
5
|
end
|
@@ -61,6 +62,30 @@ class AngryHash < Hash
|
|
61
62
|
self
|
62
63
|
end
|
63
64
|
|
65
|
+
def to_normal_hash
|
66
|
+
__to_hash(self)
|
67
|
+
end
|
68
|
+
def __to_hash(value,cycle_guard={})
|
69
|
+
return cycle_guard[value.hash] if cycle_guard.key?(value.hash)
|
70
|
+
|
71
|
+
case value
|
72
|
+
when Hash
|
73
|
+
new_hash = cycle_guard[value.hash] = {}
|
74
|
+
|
75
|
+
value.inject(new_hash) do |hash,(k,v)|
|
76
|
+
hash[k] = __to_hash(v,cycle_guard)
|
77
|
+
hash
|
78
|
+
end
|
79
|
+
when Array
|
80
|
+
new_array = cycle_guard[value.hash] = []
|
81
|
+
|
82
|
+
value.each {|v| new_array << __to_hash(v,cycle_guard)}
|
83
|
+
else
|
84
|
+
value
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
|
64
89
|
def method_missing(method,*args,&blk)
|
65
90
|
method_s = method.to_s
|
66
91
|
|
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
|
+
- 3
|
9
|
+
version: 0.0.3
|
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-04-29 00:00:00 +10:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -30,6 +30,9 @@ files:
|
|
30
30
|
- .gitignore
|
31
31
|
- Rakefile
|
32
32
|
- VERSION
|
33
|
+
- angry_hash.gemspec
|
34
|
+
- examples/creation_eg.rb
|
35
|
+
- examples/eg_helper.rb
|
33
36
|
- lib/angry_hash.rb
|
34
37
|
- lib/angry_hash/merge_string.rb
|
35
38
|
has_rdoc: true
|