casted_hash 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80a47e0dbe45026edc63a50e69adf59090ffd638
4
- data.tar.gz: 973fc8ba7cadd92869cb0667b8875c3ef500efd2
3
+ metadata.gz: 2766e44c7cab47d5330284c6277d51f28ede5436
4
+ data.tar.gz: 44787b63218ed0b0da0dea2f20bffd97c94e8649
5
5
  SHA512:
6
- metadata.gz: 1f0ff29181122f15a57bcadc791402b0010db1c186c0b44dca5dadee33276f49392712cd92d43792a7bf9b4ec2e593a2767f3ae6775e25859eb39d5e0f95b0f7
7
- data.tar.gz: 40a7606d898ef57a6671bc10a3af21f4b3a87a4fc5726ea0bb82f892a35d4761e814f6b8a5e62f4dbf9a0df38eacd58a1e3bf0662dd0e66931270e8e31fad0f4
6
+ metadata.gz: 7d1b9bb7ff8d5bf2e730fb825bacd7643f98b262731a20838a466539842c681d32fa97dc1e06c5d3a5096888a81521bd43931173f678d0d5671cb13e6d48c4fc
7
+ data.tar.gz: 5ac7495d36dcb79f6f6314190de38332075f1a8f87a7c21967cb6cb3a0a8fc6b7211248b582cff1a7c5dcc5ef4a08cca954c501260d40b254330576b39781aee
data/lib/casted_hash.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class CastedHash < Hash
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
 
4
4
  def initialize(constructor = {}, cast_proc = nil)
5
5
  raise ArgumentError, "`cast_proc` required" unless cast_proc
@@ -8,7 +8,7 @@ class CastedHash < Hash
8
8
 
9
9
  if constructor.is_a?(CastedHash)
10
10
  super()
11
- @casted_keys = constructor.instance_variable_get(:@casted_keys)
11
+ @casted_keys = constructor.instance_variable_get(:@casted_keys).dup
12
12
  regular_update(constructor)
13
13
  elsif constructor.is_a?(Hash)
14
14
  @casted_keys = []
@@ -97,7 +97,7 @@ describe CastedHash do
97
97
  end
98
98
 
99
99
  it "takes over scope when merging two casted hashes" do
100
- hash1 = CastedHash.new({:a => 1, :b => 2}, lambda {|x| x + 10 })
100
+ hash1 = CastedHash.new({:a => 1, :b => 2, :z => 0}, lambda {|x| x + 10 })
101
101
  hash2 = CastedHash.new({:a => 2, :c => 3, :d => 4}, lambda {|x| x + 100 })
102
102
 
103
103
  assert_equal 11, hash1[:a]
@@ -108,7 +108,10 @@ describe CastedHash do
108
108
 
109
109
  hash3 = hash1.merge hash2
110
110
 
111
- assert_equal ["a", "b", "c", "d"], hash3.keys
111
+ assert_equal 10, hash3[:z]
112
+ assert !hash1.casted?(:z)
113
+
114
+ assert_equal ["a", "b", "c", "d", "z"], hash3.keys.sort
112
115
  assert !hash3.casted?(:a)
113
116
  assert hash3.casted?(:b)
114
117
  assert !hash3.casted?(:c)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casted_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephan Kaag
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-24 00:00:00.000000000 Z
11
+ date: 2014-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler