nice_hash 1.12.1 → 1.12.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/lib/nice/hash/add_to_ruby.rb +28 -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: 6c8fc89de75ddcea68d453b5a4670592a3d57b7787a51be093ba6bd9719c8ce7
|
4
|
+
data.tar.gz: f89bda34d0ec0adcb5c89e678567f2ae54746d29d1f53c95838797488c95fcaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ee567360a718e195676c30b89e280acbb718e65c6c53a9bbefeba806d77e5fd99d1272a5c1e75c5e1d5f5e854e9ffc0fe71f1fde39c44a7956e3586351d5cb7
|
7
|
+
data.tar.gz: 4d1fd17c81f29f349b27fce1d43918e1fe45fa501b610987cf7ff60a8172e7712b4291b048257319024171e92279602bac9e66cd60203ca380264fd92e6e7a28
|
data/README.md
CHANGED
@@ -168,6 +168,18 @@ puts new_hash.get_values(:address, :zip) #> {:zip=>{:default=>"00000", :correct=
|
|
168
168
|
puts new_hash.get_values(:drawId) #> {:drawId=>["84914", "21158"]}
|
169
169
|
```
|
170
170
|
|
171
|
+
In case of an array of hashes, you will be able also to access the different keys, for example:
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
my_array = [{name: 'Peter', city: 'Madrid'}, {name: 'Lola', city: 'NYC'}] :
|
175
|
+
|
176
|
+
my_array.city
|
177
|
+
#> ['Madrid', 'NYC']
|
178
|
+
|
179
|
+
my_array._name
|
180
|
+
#> ['Peter', 'Lola']
|
181
|
+
```
|
182
|
+
|
171
183
|
### Change all values on the keys we specified
|
172
184
|
|
173
185
|
Supply a hash with all the keys and the values you want to change on the hash, then it will return the hash/array with the values modified at any level.
|
@@ -280,3 +280,31 @@ class Object
|
|
280
280
|
self
|
281
281
|
end
|
282
282
|
end
|
283
|
+
|
284
|
+
class Array
|
285
|
+
###########################################################################
|
286
|
+
# For Array of Hashes returns an array of values of the hash key specified in case doesn't exist an Array method with the same name
|
287
|
+
# The keys can be accessed also adding underscore to avoid problems with existent methods
|
288
|
+
# examples for the array of hashes [{name: 'Peter', city: 'Madrid'}, {name: 'Lola', city: 'NYC'}] :
|
289
|
+
# my_array.city
|
290
|
+
# my_array._name
|
291
|
+
###########################################################################
|
292
|
+
def method_missing(m, *arguments, &block)
|
293
|
+
m = m[1..-1].to_sym if m[0] == "_"
|
294
|
+
array = []
|
295
|
+
no_key = true
|
296
|
+
self.map do |hash|
|
297
|
+
if hash.is_a?(Hash)
|
298
|
+
array << hash[m]
|
299
|
+
no_key = false
|
300
|
+
else
|
301
|
+
array << nil
|
302
|
+
end
|
303
|
+
end
|
304
|
+
if no_key
|
305
|
+
super(m, *arguments, &block)
|
306
|
+
else
|
307
|
+
array
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|