nice_hash 1.10.0 → 1.10.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6531cb144b11a3373a25dbb6e091a7477db13577dbfce6270da65376c578b843
4
- data.tar.gz: 794d8a95f00d82661307c2d3c25d6cd62278101c03c69c9213f2156463c59ec3
3
+ metadata.gz: 195767f9be9278bf46697e41d73bcd8434a5e1967af96ea17ed51cbd7f92940e
4
+ data.tar.gz: 565522a2ad7ff483bb66d77316a05fd347032c462a1367e96242e9aef5021e74
5
5
  SHA512:
6
- metadata.gz: 81a602fbbdaacf401a39c28152f3af1191d485bfa3b0da94bb58a64747c52fed7539ea443a5ead5568f01162dc154d3424cff238b082f1df005bdfaf8fb2fa74
7
- data.tar.gz: deb1f88a222d9d3c13d35c6abd5836baef49c4cd1a09e2a24ad02179a76a5d0cb4d641fd2d48f1db5718dbb5bbce22b6483a91d3a7fae94a14d0e2edb1eb0c96
6
+ metadata.gz: e48e20f0333d4f9167f2de11b1565c2a6392eec09b7e1ee5c7ac31a40aa4ffb229e1236e406fa25f5cef8d30d70a9fb7102d7a88013a89f48c1fc73743542c6c
7
+ data.tar.gz: fcf95096adeb8c8672310de49301fb53504e28620b9b18da6541335c905b2c3fe56400c2b8ca26944f0d5d9538681885c98d7d7dcee42651462853d833eb8595
data/README.md CHANGED
@@ -715,7 +715,25 @@ In class `Date` we added a very handy `random` method you can use to generate ra
715
715
  puts Date.new(2003,10,31).random(Date.today)
716
716
  ```
717
717
 
718
+ If you need a clean copy of a hash use the method `deep_copy`
718
719
 
720
+ ```ruby
721
+ my_hash = {one: 1, two: 2, three: {car: 'seat'}}
722
+
723
+ my_new_hash = my_hash.deep_copy # using deep_copy method
724
+ my_new_hash[:three][:car] = 'changed'
725
+ my_new_hash[:two] = 'changed'
726
+ p my_hash
727
+ # my_hash doesn't change
728
+ #>{:one=>1, :two=>2, :three=>{:car=>"seat"}}
729
+
730
+ my_new_hash = my_hash.clone # using clone or dup or direct assignment
731
+ my_new_hash[:three][:car] = 'changed'
732
+ my_new_hash[:two] = 'changed'
733
+ p my_hash
734
+ # my_hash changed!
735
+ #>{:one=>1, :two=>2, :three=>{:car=>"changed"}}
736
+ ```
719
737
 
720
738
  ## Contributing
721
739
 
@@ -173,6 +173,14 @@ class Hash
173
173
  end
174
174
  end
175
175
 
176
+ ###########################################################################
177
+ # returns a clean copy of the hash
178
+ ###########################################################################
179
+ def deep_copy
180
+ Marshal.load(Marshal.dump(self))
181
+ end
182
+
183
+
176
184
  ###########################################################################
177
185
  # It will filter the hash by the key specified on select_hash_key.
178
186
  # In case a subhash specified on a value it will be selected only the value of the key specified on select_hash_key
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nice_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz