nice_hash 1.10.0 → 1.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/lib/nice/hash/add_to_ruby.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 195767f9be9278bf46697e41d73bcd8434a5e1967af96ea17ed51cbd7f92940e
|
4
|
+
data.tar.gz: 565522a2ad7ff483bb66d77316a05fd347032c462a1367e96242e9aef5021e74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|