Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 3 files changed
  • 0 comments
  • 1 contributor
14 lib/hashugar.rb
@@ -3,8 +3,11 @@
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   - @table[convert_key(key)] = value.to_hashugar
  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 @@ def respond_to?(key)
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
2  lib/hashugar/version.rb
... ... @@ -1,3 +1,3 @@
1 1 class Hashugar
2   - VERSION = "0.0.5"
  2 + VERSION = "0.0.6"
3 3 end
15 spec/hashugar_spec.rb
@@ -74,4 +74,19 @@
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

No commit comments for this range

Something went wrong with that request. Please try again.