hashugar 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +15 -15
- data/lib/hashugar/version.rb +1 -1
- data/lib/hashugar.rb +5 -7
- data/spec/hashugar_spec.rb +8 -0
- metadata +9 -9
data/README.md
CHANGED
@@ -29,36 +29,36 @@ Let's compare to the competitors - [OpenStruct](http://www.ruby-doc.org/stdlib-1
|
|
29
29
|
Ruby 1.9.3 benchmark
|
30
30
|
|
31
31
|
OpenStruct create small hash and access once
|
32
|
-
|
32
|
+
43858.0 (±5.5%) i/s - 221820 in 5.074250s (cycle=3697)
|
33
33
|
Hashr create small hash and access once
|
34
|
-
|
34
|
+
67408.9 (±5.0%) i/s - 339780 in 5.053728s (cycle=5663)
|
35
35
|
Hashugar create small hash and access once
|
36
|
-
|
36
|
+
230217.9 (±4.2%) i/s - 1152670 in 5.015705s (cycle=15790)
|
37
37
|
|
38
38
|
OpenStruct create big hash and access once
|
39
|
-
|
39
|
+
974.8 (±4.9%) i/s - 4949 in 5.090937s (cycle=101)
|
40
40
|
Hashr create big hash and access once
|
41
|
-
|
41
|
+
3468.1 (±5.9%) i/s - 17450 in 5.051485s (cycle=349)
|
42
42
|
Hashugar create big hash and access once
|
43
|
-
|
43
|
+
12738.3 (±2.6%) i/s - 64220 in 5.045018s (cycle=1235)
|
44
44
|
|
45
45
|
OpenStruct create small hash and access ten times
|
46
|
-
|
46
|
+
46170.2 (±2.7%) i/s - 231362 in 5.014712s (cycle=3989)
|
47
47
|
Hashr create small hash and access ten times
|
48
|
-
|
48
|
+
41818.8 (±2.5%) i/s - 210320 in 5.032433s (cycle=3824)
|
49
49
|
Hashugar create small hash and access ten times
|
50
|
-
|
50
|
+
82216.8 (±2.3%) i/s - 411742 in 5.010785s (cycle=7099)
|
51
51
|
|
52
52
|
OpenStruct create small hash and access fifty times
|
53
|
-
|
53
|
+
36126.0 (±2.8%) i/s - 182112 in 5.044983s (cycle=3252)
|
54
54
|
Hashr create small hash and access fifty times
|
55
|
-
|
55
|
+
15584.9 (±2.5%) i/s - 78312 in 5.028076s (cycle=1506)
|
56
56
|
Hashugar create small hash and access fifty times
|
57
|
-
|
57
|
+
21513.9 (±6.0%) i/s - 107952 in 5.039238s (cycle=2076)
|
58
58
|
|
59
59
|
OpenStruct create small hash and access hundred times
|
60
|
-
|
60
|
+
28617.9 (±2.7%) i/s - 144928 in 5.068069s (cycle=2588)
|
61
61
|
Hashr create small hash and access hundred times
|
62
|
-
|
62
|
+
8860.7 (±1.7%) i/s - 45103 in 5.091664s (cycle=851)
|
63
63
|
Hashugar create small hash and access hundred times
|
64
|
-
|
64
|
+
11491.3 (±2.4%) i/s - 57512 in 5.007677s (cycle=1106)
|
data/lib/hashugar/version.rb
CHANGED
data/lib/hashugar.rb
CHANGED
@@ -2,7 +2,10 @@ require "hashugar/version"
|
|
2
2
|
|
3
3
|
class Hashugar
|
4
4
|
def initialize(hash)
|
5
|
-
@table =
|
5
|
+
@table = {}
|
6
|
+
hash.each_pair do |key, value|
|
7
|
+
@table[convert_key(key)] = value.to_hashugar
|
8
|
+
end
|
6
9
|
end
|
7
10
|
|
8
11
|
def method_missing(method, *args, &block)
|
@@ -38,12 +41,7 @@ end
|
|
38
41
|
|
39
42
|
class Hash
|
40
43
|
def to_hashugar
|
41
|
-
|
42
|
-
table = {}
|
43
|
-
each_pair do |key, value|
|
44
|
-
table[convert_key(key)] = value.to_hashugar
|
45
|
-
end
|
46
|
-
Hashugar.new(table)
|
44
|
+
Hashugar.new(self)
|
47
45
|
end
|
48
46
|
|
49
47
|
private
|
data/spec/hashugar_spec.rb
CHANGED
@@ -66,4 +66,12 @@ describe Hashugar do
|
|
66
66
|
hashugar.respond_to?(:b).should be_false
|
67
67
|
end
|
68
68
|
end
|
69
|
+
|
70
|
+
context 'when creating using Hashugar#new' do
|
71
|
+
it 'should accept hash in contructor' do
|
72
|
+
hashugar = Hashugar.new({:a => {:b => 1}})
|
73
|
+
hashugar.a.b.should == 1
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
69
77
|
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.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-12-27 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &15980000 !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: *15980000
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: benchmark_suite
|
27
|
-
requirement: &
|
27
|
+
requirement: &15979540 !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: *15979540
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: ffi
|
38
|
-
requirement: &
|
38
|
+
requirement: &15978900 !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: *15978900
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: hashr
|
49
|
-
requirement: &
|
49
|
+
requirement: &15978240 !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: *15978240
|
58
58
|
description: Nested OpenStruct optimized for short-lived objects.
|
59
59
|
email:
|
60
60
|
- johno@jsmf.net
|