hashugar 0.0.3 → 0.0.4

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/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
- 47458.0 (±3.4%) i/s - 238380 in 5.029038s (cycle=4110)
32
+ 43858.0 (±5.5%) i/s - 221820 in 5.074250s (cycle=3697)
33
33
  Hashr create small hash and access once
34
- 70290.23.1%) i/s - 356240 in 5.072827s (cycle=5840)
34
+ 67408.95.0%) i/s - 339780 in 5.053728s (cycle=5663)
35
35
  Hashugar create small hash and access once
36
- 873106.5 (±4.8%) i/s - 4381784 in 5.030829s (cycle=37774)
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
- 1028.33.0%) i/s - 5202 in 5.063657s (cycle=102)
39
+ 974.84.9%) i/s - 4949 in 5.090937s (cycle=101)
40
40
  Hashr create big hash and access once
41
- 3686.62.7%) i/s - 18615 in 5.053303s (cycle=365)
41
+ 3468.15.9%) i/s - 17450 in 5.051485s (cycle=349)
42
42
  Hashugar create big hash and access once
43
- 839766.3 (±4.9%) i/s - 4199760 in 5.013690s (cycle=36840)
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
- 46554.1 (±2.8%) i/s - 234958 in 5.050963s (cycle=4051)
46
+ 46170.2 (±2.7%) i/s - 231362 in 5.014712s (cycle=3989)
47
47
  Hashr create small hash and access ten times
48
- 42768.0 (±2.4%) i/s - 216543 in 5.066085s (cycle=3799)
48
+ 41818.8 (±2.5%) i/s - 210320 in 5.032433s (cycle=3824)
49
49
  Hashugar create small hash and access ten times
50
- 121441.34.1%) i/s - 608597 in 5.021793s (cycle=9977)
50
+ 82216.82.3%) i/s - 411742 in 5.010785s (cycle=7099)
51
51
 
52
52
  OpenStruct create small hash and access fifty times
53
- 36047.5 (±2.8%) i/s - 181390 in 5.035970s (cycle=3298)
53
+ 36126.0 (±2.8%) i/s - 182112 in 5.044983s (cycle=3252)
54
54
  Hashr create small hash and access fifty times
55
- 15349.64.1%) i/s - 76752 in 5.008858s (cycle=1476)
55
+ 15584.92.5%) i/s - 78312 in 5.028076s (cycle=1506)
56
56
  Hashugar create small hash and access fifty times
57
- 23561.9 (±7.4%) i/s - 117250 in 5.005844s (cycle=2345)
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
- 27801.25.8%) i/s - 139194 in 5.027806s (cycle=2442)
60
+ 28617.92.7%) i/s - 144928 in 5.068069s (cycle=2588)
61
61
  Hashr create small hash and access hundred times
62
- 8223.7 (±6.0%) i/s - 41463 in 5.061138s (cycle=813)
62
+ 8860.7 (±1.7%) i/s - 45103 in 5.091664s (cycle=851)
63
63
  Hashugar create small hash and access hundred times
64
- 12406.03.8%) i/s - 61984 in 5.004111s (cycle=1192)
64
+ 11491.32.4%) i/s - 57512 in 5.007677s (cycle=1106)
@@ -1,3 +1,3 @@
1
1
  class Hashugar
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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 = hash
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
- # TODO lazy?
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
@@ -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.3
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: &19545860 !ruby/object:Gem::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: *19545860
24
+ version_requirements: *15980000
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: benchmark_suite
27
- requirement: &19545380 !ruby/object:Gem::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: *19545380
35
+ version_requirements: *15979540
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ffi
38
- requirement: &19544920 !ruby/object:Gem::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: *19544920
46
+ version_requirements: *15978900
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: hashr
49
- requirement: &19544220 !ruby/object:Gem::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: *19544220
57
+ version_requirements: *15978240
58
58
  description: Nested OpenStruct optimized for short-lived objects.
59
59
  email:
60
60
  - johno@jsmf.net