casted_hash 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/casted_hash.rb +10 -9
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7d1e26f467044a7d5b7d059f7553d841550b95f
4
- data.tar.gz: f905c88e348f9a48a0cdd73539dcc5403604cd9e
3
+ metadata.gz: 50e91b47f2183e145bf15c2f98b9c226f54f0f7b
4
+ data.tar.gz: 6f9ad44cb0d894e88cd7ee5a3d1ecb1400db1197
5
5
  SHA512:
6
- metadata.gz: 6143460aa9445965acd03318c3d4dfe65745b9804e09eecca3aae92b75be208f803ae9da4f2065a1973ed2c14e010d85ec1f99758c8581fa399fc3c611a457ae
7
- data.tar.gz: 9e2ef962d99a8e1438bbde9c6bd8b59dfa05327a9a184fdbf514cb168f3a3b47541d6e80c71f8a416f7f1f9c8ebefe2777ffacdd0495be69949b066c6b9b2e81
6
+ metadata.gz: e3c431b50dfeef9412ba54ac62896978edf6a2aa050e16b8d61fe38c856736227e8f7628c0b11262f2ae8945b7fbf862a292d0af26ae4d93388df76c015bb476
7
+ data.tar.gz: 5e68e7c4468f8583796a2363965fa8b763ff9c470d898eea9b12c567c5cc1330a074a3c74a50bead0c9f50969e7ae888274919c127b66e5a34e14efedb26d6cd
data/lib/casted_hash.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class CastedHash < Hash
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
 
4
4
  def initialize(constructor = {}, cast_proc = nil)
5
5
  raise ArgumentError, "`cast_proc` required" unless cast_proc
@@ -47,13 +47,16 @@ class CastedHash < Hash
47
47
  end
48
48
  end
49
49
 
50
- alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
50
+ alias_method :original_regular_writer, :[]=
51
51
  alias_method :regular_update, :update unless method_defined?(:regular_update)
52
52
 
53
+ def regular_writer(key, value)
54
+ original_regular_writer(convert_key(key), value)
55
+ end
56
+
53
57
  def []=(key, value)
54
- key = convert_key(key)
55
- uncast! key
56
- regular_writer(key, value)
58
+ uncast! convert_key(key)
59
+ regular_writer key, value
57
60
  end
58
61
 
59
62
  alias_method :store, :[]=
@@ -66,14 +69,12 @@ class CastedHash < Hash
66
69
  return self if other_hash.empty?
67
70
 
68
71
  other_hash.each_pair do |key, value|
69
- converted_key = convert_key(key)
70
-
71
- regular_writer converted_key, value
72
+ regular_writer key, value
72
73
 
73
74
  if other_hash.is_a?(CastedHash) && other_hash.casted?(key)
74
75
  casted!(key)
75
76
  elsif casted?(key)
76
- uncast!(converted_key)
77
+ uncast!(convert_key(key))
77
78
  end
78
79
  end
79
80
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casted_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephan Kaag