hashugar 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hashugar.rb +8 -6
- data/lib/hashugar/version.rb +1 -1
- data/spec/hashugar_spec.rb +15 -0
- metadata +10 -10
data/lib/hashugar.rb
CHANGED
@@ -3,8 +3,11 @@ require "hashugar/version"
|
|
3
3
|
class Hashugar
|
4
4
|
def initialize(hash)
|
5
5
|
@table = {}
|
6
|
+
@table_with_original_keys = {}
|
6
7
|
hash.each_pair do |key, value|
|
7
|
-
|
8
|
+
hashugar = value.to_hashugar
|
9
|
+
@table_with_original_keys[key] = hashugar
|
10
|
+
@table[convert_key(key)] = hashugar
|
8
11
|
end
|
9
12
|
end
|
10
13
|
|
@@ -33,6 +36,10 @@ class Hashugar
|
|
33
36
|
@table.has_key?(convert_key(key))
|
34
37
|
end
|
35
38
|
|
39
|
+
def each(&block)
|
40
|
+
@table_with_original_keys.each(&block)
|
41
|
+
end
|
42
|
+
|
36
43
|
private
|
37
44
|
def convert_key(key)
|
38
45
|
key.is_a?(Symbol) ? key.to_s : key
|
@@ -43,11 +50,6 @@ class Hash
|
|
43
50
|
def to_hashugar
|
44
51
|
Hashugar.new(self)
|
45
52
|
end
|
46
|
-
|
47
|
-
private
|
48
|
-
def convert_key(key)
|
49
|
-
key.is_a?(Symbol) ? key.to_s : key
|
50
|
-
end
|
51
53
|
end
|
52
54
|
|
53
55
|
class Array
|
data/lib/hashugar/version.rb
CHANGED
data/spec/hashugar_spec.rb
CHANGED
@@ -74,4 +74,19 @@ describe Hashugar do
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
+
context 'when enumerating' do
|
78
|
+
it 'should act like normal hash' do
|
79
|
+
hashugar = Hashugar.new({:a => 4, :c => 2})
|
80
|
+
|
81
|
+
keys = []
|
82
|
+
values = []
|
83
|
+
hashugar.each do |k, v|
|
84
|
+
keys << k
|
85
|
+
values << v
|
86
|
+
end
|
87
|
+
|
88
|
+
keys.should == [:a, :c]
|
89
|
+
values.should == [4, 2]
|
90
|
+
end
|
91
|
+
end
|
77
92
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashugar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &19350000 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *19350000
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: benchmark_suite
|
27
|
-
requirement: &
|
27
|
+
requirement: &19348020 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *19348020
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: ffi
|
38
|
-
requirement: &
|
38
|
+
requirement: &19365580 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *19365580
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: hashr
|
49
|
-
requirement: &
|
49
|
+
requirement: &19674140 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *19674140
|
58
58
|
description: Nested OpenStruct optimized for short-lived objects.
|
59
59
|
email:
|
60
60
|
- johno@jsmf.net
|