nice_hash 1.11.1 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -0
- data/lib/nice/hash/add_to_ruby.rb +22 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84c78765e9b19e8f5d4774a405e7af03b5f4b47bf9562cf0fa8bc2a6e4a864ee
|
4
|
+
data.tar.gz: 461884a6c109548e01e81df000c41720d1cf5ddfa749e2a1dd3598aa2b619309
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99b063ff060a231d93f114e1c2187946b5bd22e147e1f9e1ce8c6ed33a464b7437ce75154e96cdc6f5c844f067319aca879118d4f80de7b34d59ffbd6cb84c9b
|
7
|
+
data.tar.gz: c78f0ba9daa0ef799df4996a4df3140bfe1222cefd4b75c9735748d7e31ee8bdf557681cef5cc7e905af1109af2d862156cc8f901a35077622f79f936d4b2f0b
|
data/README.md
CHANGED
@@ -167,6 +167,19 @@ puts new_hash.get_values(:address) #> {:address=>"21 Doom Av"}
|
|
167
167
|
puts new_hash.get_values(:address, :zip) #> {:zip=>{:default=>"00000", :correct=>"42782"}, :address=>"21 Doom Av"}
|
168
168
|
puts new_hash.get_values(:drawId) #> {:drawId=>["84914", "21158"]}
|
169
169
|
```
|
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
|
+
|
170
183
|
### Change all values on the keys we specified
|
171
184
|
|
172
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,25 @@ 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
|
+
self.map do |hash|
|
296
|
+
if hash.is_a?(Hash)
|
297
|
+
array << hash[m]
|
298
|
+
else
|
299
|
+
array << nil
|
300
|
+
end
|
301
|
+
end
|
302
|
+
array
|
303
|
+
end
|
304
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nice_hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: string_pattern
|