darthjee-core_ext 1.7.4 → 2.0.0
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 +4 -4
- data/.circleci/config.yml +7 -1
- data/.gitignore +2 -0
- data/.reek.yml +3 -0
- data/ARRAY_README.md +72 -15
- data/CLASS_README.md +154 -0
- data/DATE_README.md +19 -9
- data/Dockerfile +2 -5
- data/ENUMERABLE_README.md +154 -4
- data/HASH_README.md +276 -135
- data/MATH_README.md +14 -10
- data/OBJECT_README.md +18 -35
- data/README.md +8 -4
- data/Rakefile +1 -0
- data/SYMBOL_README.md +13 -18
- data/config/rubycritc.rb +12 -0
- data/config/yardstick.yml +45 -3
- data/core_ext.gemspec +10 -8
- data/docker-compose.yml +15 -7
- data/lib/darthjee/core_ext/array.rb +17 -12
- data/lib/darthjee/core_ext/array/hash_builder.rb +20 -4
- data/lib/darthjee/core_ext/class.rb +28 -10
- data/lib/darthjee/core_ext/date.rb +1 -0
- data/lib/darthjee/core_ext/enumerable.rb +67 -30
- data/lib/darthjee/core_ext/hash.rb +4 -2
- data/lib/darthjee/core_ext/hash/cameliazable.rb +39 -8
- data/lib/darthjee/core_ext/hash/chain_fetcher.rb +17 -1
- data/lib/darthjee/core_ext/hash/changeable.rb +88 -0
- data/lib/darthjee/core_ext/hash/deep_hash_constructor.rb +127 -63
- data/lib/darthjee/core_ext/hash/deep_hash_constructor/setter.rb +112 -0
- data/lib/darthjee/core_ext/hash/key_changeable.rb +126 -54
- data/lib/darthjee/core_ext/hash/key_changer.rb +140 -40
- data/lib/darthjee/core_ext/hash/keys_sorter.rb +42 -6
- data/lib/darthjee/core_ext/hash/squasher.rb +131 -18
- data/lib/darthjee/core_ext/hash/transformable.rb +133 -41
- data/lib/darthjee/core_ext/hash/transposeable.rb +37 -8
- data/lib/darthjee/core_ext/hash/value_changer.rb +76 -36
- data/lib/darthjee/core_ext/math.rb +37 -6
- data/lib/darthjee/core_ext/numeric.rb +10 -0
- data/lib/darthjee/core_ext/object.rb +29 -0
- data/lib/darthjee/core_ext/symbol.rb +22 -2
- data/lib/darthjee/core_ext/version.rb +1 -1
- data/scripts/check_readme.sh +6 -0
- data/scripts/rubycritic.sh +10 -0
- data/spec/integration/readme/array_spec.rb +96 -0
- data/spec/integration/readme/class_spec.rb +123 -0
- data/spec/integration/readme/date_spec.rb +20 -0
- data/spec/integration/readme/enumerable_spec.rb +87 -0
- data/spec/integration/readme/hash_spec.rb +391 -0
- data/spec/integration/readme/math_spec.rb +31 -0
- data/spec/integration/readme/object_spec.rb +49 -0
- data/spec/integration/readme/symbol_spec.rb +29 -0
- data/spec/integration/yard/darthjee/core_ext/enumerable_spec.rb +24 -4
- data/spec/integration/yard/darthjee/core_ext/hash/cameliazable_spec.rb +11 -0
- data/spec/integration/yard/darthjee/core_ext/hash/changeable_spec.rb +68 -0
- data/spec/integration/yard/darthjee/core_ext/hash/deep_hash_constructor/setter_spec.rb +34 -0
- data/spec/integration/yard/darthjee/core_ext/hash/deep_hash_constructor_spec.rb +65 -0
- data/spec/integration/yard/darthjee/core_ext/hash/key_changeable_spec.rb +8 -0
- data/spec/integration/yard/darthjee/core_ext/hash/key_changer_spec.rb +59 -0
- data/spec/integration/yard/darthjee/core_ext/hash/keys_sorter_spec.rb +25 -0
- data/spec/integration/yard/darthjee/core_ext/hash/squasher_spec.rb +60 -0
- data/spec/integration/yard/darthjee/core_ext/hash/transformable_spec.rb +66 -36
- data/spec/integration/yard/darthjee/core_ext/hash/transposeable_spec.rb +35 -0
- data/spec/integration/yard/darthjee/core_ext/hash_spec.rb +13 -2
- data/spec/integration/yard/darthjee/core_ext/math_spec.rb +28 -0
- data/spec/integration/yard/darthjee/core_ext/numeric_spec.rb +11 -0
- data/spec/integration/yard/darthjee/core_ext/object_spec.rb +47 -0
- data/spec/integration/yard/darthjee/core_ext/symbol_spec.rb +17 -0
- data/spec/lib/darthjee/core_ext/hash/deep_hash_constructor/setter_spec.rb +64 -0
- data/spec/lib/darthjee/core_ext/hash/deep_hash_constructor_spec.rb +16 -156
- data/spec/lib/darthjee/core_ext/hash/keys_sorter_spec.rb +5 -4
- data/spec/lib/darthjee/core_ext/hash/squasher_spec.rb +8 -2
- data/spec/lib/darthjee/core_ext/hash/value_changer_spec.rb +4 -12
- data/spec/lib/hash_spec.rb +92 -146
- data/spec/lib/object_spec.rb +32 -0
- data/spec/support/models/client.rb +22 -0
- data/spec/support/shared_examples/hash/deep_hash.rb +166 -0
- data/spec/support/shared_examples/hash/hash_squasher.rb +54 -9
- data/spec/support/shared_examples/hash/keys_sorter.rb +266 -6
- metadata +70 -8
- data/lib/darthjee/core_ext/hash/to_hash_mapper.rb +0 -25
- data/spec/lib/darthjee/core_ext/hash/to_hash_mapper_spec.rb +0 -11
data/HASH_README.md
CHANGED
@@ -1,195 +1,248 @@
|
|
1
1
|
## Hash
|
2
|
-
### #map_to_hash
|
3
|
-
map returning a hash with the original keys
|
4
|
-
|
5
|
-
```ruby
|
6
|
-
hash = { a: 1, b: 2 }
|
7
|
-
hash.map_to_hash { |k, v| "#{k}_#{v}" }
|
8
|
-
{ a: "a_1", b: "b_2" }
|
9
|
-
```
|
10
2
|
|
11
|
-
### #
|
12
|
-
|
3
|
+
### #append_to_keys
|
4
|
+
Change each keys appending an string
|
13
5
|
|
14
6
|
```ruby
|
15
|
-
{
|
16
|
-
|
7
|
+
{ key: 1 }.append_to_keys 's'
|
8
|
+
|
9
|
+
# returns { keys: 1 }
|
17
10
|
```
|
18
11
|
|
19
|
-
|
12
|
+
### #camelize_keys
|
13
|
+
Change the keys camelizing them and accepting parameters:
|
14
|
+
- uppercase_first_letter: Use the java or javascript format (default: true)
|
15
|
+
- recursive: when true, does it recursivly through inner arrays (default: true)
|
20
16
|
|
21
17
|
```ruby
|
22
|
-
|
23
|
-
h.chain_fetch(:a, :x, :y, :z) { |key, missed_keys| "returned #{key}" }
|
24
|
-
'returned x'
|
25
|
-
```
|
18
|
+
hash = { ca_b: 1, k: [{ a_b: 1 }] }
|
26
19
|
|
27
|
-
|
28
|
-
|
20
|
+
hash.camelize_keys # return { CaB: 1, K: [{ AB: 1 }] }
|
21
|
+
```
|
29
22
|
|
30
23
|
```ruby
|
31
|
-
|
24
|
+
hash = { ca_b: 1, k: [{ a_b: 1 }] }
|
25
|
+
|
26
|
+
hash.camelize_keys(recursive: false)
|
27
|
+
# returns { CaB: 1, K: [{ a_b: 1 }] }
|
32
28
|
```
|
33
|
-
|
29
|
+
|
34
30
|
```ruby
|
35
|
-
|
36
|
-
```
|
31
|
+
hash = { ca_b: 1, k: [{ a_b: 1 }] }
|
37
32
|
|
38
|
-
|
39
|
-
Changes a hash spliting keys into inner hashs
|
33
|
+
hash.camelize_keys(uppercase_first_letter: false)
|
40
34
|
|
41
|
-
|
42
|
-
{ 'a.b' => 1 }.to_deep_hash
|
43
|
-
```
|
44
|
-
returns
|
45
|
-
```ruby
|
46
|
-
{ 'a' => { 'b' => 1 } }
|
35
|
+
# returns { caB: 1, k: [{ aB: 1 }] }
|
47
36
|
```
|
48
37
|
|
49
|
-
### #
|
50
|
-
Change the
|
51
|
-
|
38
|
+
### #camelize_keys!
|
39
|
+
Change the keys camelizing them and accepting parameters:
|
40
|
+
- uppercase_first_letter: Use the java or javascript format (default: true)
|
41
|
+
- recursive: when true, does it recursivly through inner arrays (default: true)
|
52
42
|
|
53
43
|
```ruby
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
44
|
+
hash = { ca_b: 1, k: [{ a_b: 1 }] }
|
45
|
+
|
46
|
+
hash.camelize_keys!
|
47
|
+
|
48
|
+
# changes hash to { CaB: 1, K: [{ AB: 1 }] }
|
59
49
|
```
|
60
50
|
|
61
51
|
```ruby
|
62
|
-
|
52
|
+
hash = { ca_b: 1, k: [{ a_b: 1 }] }
|
53
|
+
|
54
|
+
hash.camelize_keys!(recursive: false)
|
55
|
+
|
56
|
+
# changes hash to { CaB: 1, K: [{ a_b: 1 }] }
|
63
57
|
```
|
64
|
-
|
58
|
+
|
65
59
|
```ruby
|
66
|
-
|
60
|
+
hash = { ca_b: 1, k: [{ a_b: 1 }] }
|
61
|
+
|
62
|
+
hash.camelize_keys!(uppercase_first_letter: false)
|
63
|
+
|
64
|
+
# changes hash to { caB: 1, k: [{ aB: 1 }] }
|
67
65
|
```
|
68
66
|
|
69
67
|
### #chain_change_keys
|
70
|
-
|
68
|
+
Returns new hash changing the keys using a chained method call
|
71
69
|
|
72
70
|
```ruby
|
73
|
-
|
74
|
-
|
75
|
-
returns
|
76
|
-
```ruby
|
77
|
-
{ CA_B: 1 }
|
71
|
+
{ ca_b: 1 }.chain_change_keys(:to_s, :upcase, :to_sym)
|
72
|
+
|
73
|
+
# returns { CA_B: 1 }
|
78
74
|
```
|
79
75
|
|
80
|
-
### #
|
81
|
-
Change the keys
|
82
|
-
- uppercase_first_letter: Use the java or javascript format (default: true)
|
83
|
-
- recursive: when true, does it recursivly through inner arrays (default: true)
|
76
|
+
### #chain_change_keys!
|
77
|
+
Change the hash keys using a chained method call
|
84
78
|
|
85
79
|
```ruby
|
86
|
-
|
87
|
-
```
|
88
|
-
returns
|
89
|
-
```ruby
|
90
|
-
{:CaB=>1, :K=>[{:AB=>1}]}
|
91
|
-
```
|
80
|
+
{ ca_b: 1 }.chain_change_keys!(:to_s, :upcase, :to_sym)
|
92
81
|
|
93
|
-
|
94
|
-
{ ca_b: 1, k: [{ a_b: 1 }] }.camelize_keys(recursive: false)
|
95
|
-
```
|
96
|
-
returns
|
97
|
-
```ruby
|
98
|
-
{:CaB=>1, :K=>[{:a_b=>1}]}
|
82
|
+
# changes hash to { CA_B: 1 }
|
99
83
|
```
|
100
84
|
|
85
|
+
### #chain_fetch
|
86
|
+
Applies fetch in a chain
|
87
|
+
|
101
88
|
```ruby
|
102
|
-
|
89
|
+
hash = { a: { b: { c: { d: 10 } } } }
|
90
|
+
|
91
|
+
hash.chain_fetch(:a, :b, :c, :d) # returns 10
|
103
92
|
```
|
104
|
-
|
93
|
+
|
94
|
+
A block can be passed so that when a key is not found, the block will define the value to be returned
|
95
|
+
|
105
96
|
```ruby
|
106
|
-
|
97
|
+
hash = { a: { b: { c: { d: 10 } } } }
|
98
|
+
|
99
|
+
hash.chain_fetch(:a, :x, :y, :z) do |key, missed_keys|
|
100
|
+
"returned: #{key}\nmissed: [#{missed_keys.join(',')}]"
|
101
|
+
end
|
102
|
+
|
103
|
+
# returns "returned x\nmissed: [y,z]"
|
107
104
|
```
|
108
105
|
|
109
|
-
### #
|
110
|
-
|
106
|
+
### #change_keys
|
107
|
+
Change the array keys using a block accepting parameters:
|
108
|
+
- recursive: when true, does it recursivly through inner arrays (default: true)
|
111
109
|
|
112
110
|
```ruby
|
113
|
-
|
111
|
+
{ ca_b: 1, k: [{ a_b: 1 }] }.change_keys { |k| k.to_s.upcase }
|
112
|
+
|
113
|
+
# reutrns {"CA_B"=>1, "K"=>[{"A_B"=>1}]}
|
114
114
|
```
|
115
|
-
|
115
|
+
|
116
116
|
```ruby
|
117
|
-
|
117
|
+
{ ca_b: 1, k: [{ a_b: 1 }] }.change_keys(recursive: false) { |k| k.to_s.upcase }
|
118
|
+
|
119
|
+
# returns {"CA_B"=>1, "K"=>[{:a_b=>1}]}
|
118
120
|
```
|
119
121
|
|
120
|
-
### #
|
121
|
-
Change the keys
|
122
|
+
### #change_keys!
|
123
|
+
Change the array keys using a block accepting parameters:
|
122
124
|
- recursive: when true, does it recursivly through inner arrays (default: true)
|
123
125
|
|
124
126
|
```ruby
|
125
|
-
|
127
|
+
{ ca_b: 1, k: [{ a_b: 1 }] }.change_keys! { |k| k.to_s.upcase }
|
128
|
+
|
129
|
+
# changes hash to {"CA_B"=>1, "K"=>[{"A_B"=>1}]}
|
126
130
|
```
|
127
|
-
|
131
|
+
|
128
132
|
```ruby
|
129
|
-
{ca_b: 1,
|
133
|
+
{ ca_b: 1, k: [{ a_b: 1 }] }.change_keys!(recursive: false) { |k| k.to_s.upcase }
|
134
|
+
|
135
|
+
# changes hash to {"CA_B"=>1, "K"=>[{:a_b=>1}]}
|
130
136
|
```
|
131
137
|
|
132
138
|
### #change_values
|
133
|
-
|
139
|
+
Returns new hash changing the values of the hash, accepting parametes:
|
134
140
|
- recursive: when true, does it recursivly through inner arrays and hashes (default: true)
|
135
141
|
- skip_inner: when true, do not call the block for iterators such as Hash and Arrays (default: true)
|
136
142
|
|
137
143
|
```ruby
|
138
|
-
|
139
|
-
```
|
140
|
-
returns
|
141
|
-
```ruby
|
142
|
-
{ a: '2' b: [{ c: '3' }] }
|
143
|
-
```
|
144
|
+
hash = { a: 1, b: [{ c: 2 }] }
|
144
145
|
|
145
|
-
|
146
|
-
|
146
|
+
hash.change_values { |v| (v+1).to_s }
|
147
|
+
|
148
|
+
# returns { a: '2', b: [{ c: '3' }] }
|
147
149
|
```
|
148
|
-
|
150
|
+
|
149
151
|
```ruby
|
150
|
-
|
152
|
+
hash = { a: 1, b: [{ c: 2 }] }
|
153
|
+
hash.change_values(recursive: false) { |v| (v+1).to_s }
|
154
|
+
|
155
|
+
# returns { a: '2' b: [{ c: 2 }] }
|
151
156
|
```
|
152
157
|
|
153
158
|
```ruby
|
154
|
-
|
155
|
-
|
159
|
+
hash = { a: 1, b: [{ c: 2 }], d: { e: 3 } }
|
160
|
+
hash.change_values(skip_inner: false) do |v|
|
161
|
+
case value
|
162
|
+
when Integer
|
163
|
+
(value + 1).to_s
|
164
|
+
when Hash
|
165
|
+
value.to_s
|
166
|
+
else
|
167
|
+
value.class
|
156
168
|
end
|
169
|
+
end
|
170
|
+
|
171
|
+
# returns { a: '2' b: Array, d: "{:e=>3}" }
|
157
172
|
```
|
158
|
-
|
173
|
+
|
174
|
+
### #change_values!
|
175
|
+
Change the values of the hash accepting parametes:
|
176
|
+
- recursive: when true, does it recursivly through inner arrays and hashes (default: true)
|
177
|
+
- skip_inner: when true, do not call the block for iterators such as Hash and Arrays (default: true)
|
178
|
+
|
159
179
|
```ruby
|
160
|
-
|
161
|
-
```
|
180
|
+
hash = { a: 1, b: [{ c: 2 }] }
|
162
181
|
|
163
|
-
|
164
|
-
|
182
|
+
hash.change_values! { |v| (v+1).to_s }
|
183
|
+
|
184
|
+
# changes hash to { a: '2', b: [{ c: '3' }] }
|
185
|
+
```
|
165
186
|
|
166
187
|
```ruby
|
167
|
-
|
188
|
+
hash = { a: 1, b: [{ c: 2 }] }
|
189
|
+
hash.change_values!(recursive: false) { |v| (v+1).to_s }
|
190
|
+
|
191
|
+
# changes hash to { a: '2' b: [{ c: 2 }] }
|
168
192
|
```
|
169
|
-
|
193
|
+
|
170
194
|
```ruby
|
171
|
-
|
195
|
+
hash = { a: 1, b: [{ c: 2 }], d: { e: 3 } }
|
196
|
+
hash.change_values!(skip_inner: false) do |v|
|
197
|
+
case value
|
198
|
+
when Integer
|
199
|
+
(value + 1).to_s
|
200
|
+
when Hash
|
201
|
+
value.to_s
|
202
|
+
else
|
203
|
+
value.class
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
# changes hash to { a: '2' b: Array, d: "{:e=>3}" }
|
172
208
|
```
|
173
|
-
|
174
|
-
|
209
|
+
|
210
|
+
### #exclusive_merge
|
211
|
+
Like #merge but only for existing keys
|
175
212
|
|
176
213
|
```ruby
|
177
|
-
|
214
|
+
{ a: 1, b: 2 }.exclusive_merge(b: 3, c: 4)
|
215
|
+
|
216
|
+
# returns { a: 1, b: 3 }
|
178
217
|
```
|
179
|
-
|
218
|
+
|
219
|
+
### #exclusive_merge!
|
220
|
+
Like #merge! but only for existing keys
|
221
|
+
|
180
222
|
```ruby
|
181
|
-
|
223
|
+
{ a: 1, b: 2 }.exclusive_merge!(b: 3, c: 4)
|
224
|
+
|
225
|
+
# changes hash to { a: 1, b: 3 }
|
182
226
|
```
|
183
227
|
|
184
|
-
### #
|
185
|
-
|
228
|
+
### #lower_camelize_keys
|
229
|
+
Alias for [#camelize_keys](camelize_keys)(uppercase_first_letter: false)
|
186
230
|
|
187
231
|
```ruby
|
188
|
-
|
232
|
+
hash = { ca_b: 1, k: [{ a_b: 1 }] }
|
233
|
+
|
234
|
+
hash.lower_camelize_keys
|
235
|
+
# returns { caB: 1, k: [{ aB: 1 }] }
|
189
236
|
```
|
190
|
-
|
237
|
+
|
238
|
+
### #lower_camelize_keys!
|
239
|
+
Alias for [#camelize_keys](camelize_keys)(uppercase_first_letter: false)
|
240
|
+
|
191
241
|
```ruby
|
192
|
-
|
242
|
+
hash = { ca_b: 1, k: [{ a_b: 1 }] }
|
243
|
+
|
244
|
+
hash.lower_camelize_keys!
|
245
|
+
# changes hash to { caB: 1, k: [{ aB: 1 }] }
|
193
246
|
```
|
194
247
|
|
195
248
|
### #map_to_hash
|
@@ -197,58 +250,104 @@ map returning a hash with the original keys for keys
|
|
197
250
|
|
198
251
|
```ruby
|
199
252
|
hash = { a: 1, b: 2 }
|
253
|
+
|
200
254
|
hash.map_to_hash { |k, v| "#{k}_#{v}" }
|
201
|
-
|
255
|
+
|
256
|
+
# returns { a: 'a_1', b: 'b_2' }
|
257
|
+
```
|
258
|
+
|
259
|
+
### #prepend_to_keys
|
260
|
+
Change each keys prepending an string
|
261
|
+
|
262
|
+
```ruby
|
263
|
+
{ key: 1 }.prepend_to_keys 'scope:'
|
264
|
+
|
265
|
+
# returns { :'scope:key' => 1 }
|
202
266
|
```
|
203
267
|
|
204
268
|
### #remap_keys
|
205
|
-
|
269
|
+
Returns new hash changing the keys of the hash based
|
270
|
+
on a map of { old: new } value
|
206
271
|
|
207
272
|
```ruby
|
208
273
|
hash = { a: 1, b: 2 }
|
209
274
|
hash.remap_keys(a: :c, d: :e)
|
210
|
-
|
275
|
+
|
276
|
+
# returns { c: 1, b: 2, e: nil }
|
211
277
|
```
|
212
278
|
|
213
|
-
### #
|
214
|
-
|
279
|
+
### #remap_keys!
|
280
|
+
Changes the keys of the hash based on a map of { old: new } value
|
215
281
|
|
216
282
|
```ruby
|
217
|
-
{ a: 1, b: 2 }
|
218
|
-
|
283
|
+
hash = { a: 1, b: 2 }
|
284
|
+
hash.remap_keys!(a: :c, d: :e)
|
285
|
+
|
286
|
+
# change hash to { c: 1, b: 2, e: nil }
|
219
287
|
```
|
220
288
|
|
221
|
-
### #
|
222
|
-
|
289
|
+
### #sort_keys
|
290
|
+
Sort the hash usig the keys
|
291
|
+
|
223
292
|
```ruby
|
224
|
-
{
|
293
|
+
{ b: 1, a: 2 }.sort_keys.keys
|
294
|
+
|
295
|
+
# returns [:a, :b]
|
225
296
|
```
|
226
|
-
|
297
|
+
|
298
|
+
### #sort_keys!
|
299
|
+
Sort the hash usig the keys
|
300
|
+
|
227
301
|
```ruby
|
228
|
-
|
302
|
+
hash = { b: 1, a: 2 }
|
303
|
+
hash.sort_keys
|
304
|
+
hash.keys
|
305
|
+
|
306
|
+
# returns [:a, :b]
|
229
307
|
```
|
230
308
|
|
231
|
-
### #
|
232
|
-
|
309
|
+
### #squash
|
310
|
+
Squash a deep hash into a simple level hash
|
233
311
|
|
234
312
|
```ruby
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
@v = v
|
239
|
-
end
|
240
|
-
end
|
241
|
-
hash = { a: Ob.new, b: Ob.new(false), c: Ob.new(1), d: Ob.new(3) }
|
313
|
+
{ a: { b: [1, 2] } }.squash
|
314
|
+
|
315
|
+
#returns { 'a.b[0]' => 1, 'a.b[1]' => 2 }
|
242
316
|
```
|
243
317
|
|
318
|
+
### #squash!
|
319
|
+
Squash a deep hash into a simple level hash
|
320
|
+
|
244
321
|
```ruby
|
245
|
-
|
246
|
-
|
322
|
+
{ a: { b: [1, 2] } }.squash!
|
323
|
+
|
324
|
+
# changes hash to { 'a.b[0]' => 1, 'a.b[1]' => 2 }
|
325
|
+
```
|
326
|
+
|
327
|
+
### #underscore_keys
|
328
|
+
Creates a new hash changing keys from camelcase to snakecase (underscore)
|
329
|
+
|
330
|
+
options:
|
331
|
+
- recursive: when true, does it recursivly through inner arrays (default: true)
|
332
|
+
|
333
|
+
```ruby
|
334
|
+
hash = { Ca_B: 1, 'kB' => [{ KeysHash: 1 }] }
|
335
|
+
|
336
|
+
hash.underscore_keys
|
337
|
+
# returns { ca_b: 1, 'k_b' => [{ keys_hash: 1 }] }
|
247
338
|
```
|
248
339
|
|
340
|
+
### #underscore_keys!
|
341
|
+
Change the keys from camelcase to snakecase (underscore)
|
342
|
+
|
343
|
+
options:
|
344
|
+
- recursive: when true, does it recursivly through inner arrays (default: true)
|
345
|
+
|
249
346
|
```ruby
|
250
|
-
hash
|
251
|
-
|
347
|
+
hash = { Ca_B: 1, 'kB' => [{ KeysHash: 1 }] }
|
348
|
+
|
349
|
+
hash.underscore_keys!
|
350
|
+
# changes hash to { ca_b: 1, 'k_b' => [{ keys_hash: 1 }] }
|
252
351
|
```
|
253
352
|
|
254
353
|
### #transpose
|
@@ -256,10 +355,52 @@ swap keys with values of the hash
|
|
256
355
|
|
257
356
|
```ruby
|
258
357
|
{ a: 1, b: :a, c: [2, 3] }.transpose
|
358
|
+
|
359
|
+
# returns { 1 => :a, a: :b, [2, 3] => :c }
|
259
360
|
```
|
260
361
|
|
261
|
-
|
362
|
+
### #transpose!
|
363
|
+
Changes hash swapping keys with values of the hash
|
262
364
|
|
263
365
|
```ruby
|
264
|
-
{ 1
|
366
|
+
{ a: 1, b: :a, c: [2, 3] }.transpose!
|
367
|
+
|
368
|
+
# changes hash to { 1 => :a, a: :b, [2, 3] => :c }
|
265
369
|
```
|
370
|
+
|
371
|
+
### #to_deep_hash
|
372
|
+
Changes a hash spliting keys into inner hashs
|
373
|
+
|
374
|
+
```ruby
|
375
|
+
hash = { 'a.b[0]' => 1, 'a.b[1]' => 2 }
|
376
|
+
hash.to_deep_hash
|
377
|
+
|
378
|
+
# returns { 'a' => { 'b' => 1 } }
|
379
|
+
```
|
380
|
+
|
381
|
+
### #to_deep_hash!
|
382
|
+
Changes a hash spliting keys into inner hashs
|
383
|
+
|
384
|
+
```ruby
|
385
|
+
hash = { 'a.b[0]' => 1, 'a.b[1]' => 2 }
|
386
|
+
hash.to_deep_hash!
|
387
|
+
|
388
|
+
# changes hash to { 'a' => { 'b' => 1 } }
|
389
|
+
```
|
390
|
+
|
391
|
+
## Added by Enumerable
|
392
|
+
- [#clean](ENUMERABLE_README.md#clean)
|
393
|
+
- [#clean!](ENUMERABLE_README.md#clean!)
|
394
|
+
- [#map_and_find](ENUMERABLE_README.md#map_and_find)
|
395
|
+
- [#map_and_select](ENUMERABLE_README.md#map_and_select)
|
396
|
+
- [#map_to_hash](ENUMERABLE_README.md#map_to_hash)
|
397
|
+
|
398
|
+
## Added by Object
|
399
|
+
- [#is_any?](OBJECT_README.md#is_any?)
|
400
|
+
- [#trueful?](OBJECT_README.md#trueful?)
|
401
|
+
|
402
|
+
## Added by Class
|
403
|
+
- [.default_value](CLASS_README.md#default_value)
|
404
|
+
- [.default_values](CLASS_README.md#default_values)
|
405
|
+
- [.default_reader](CLASS_README.md#default_reader)
|
406
|
+
- [.default_readers](CLASS_README.md#default_readers)
|