hashlib 0.0.33 → 0.0.34
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hashlib.rb +25 -17
- metadata +2 -2
data/lib/hashlib.rb
CHANGED
@@ -118,8 +118,13 @@ class Hash
|
|
118
118
|
|
119
119
|
# arrayify all paths
|
120
120
|
path = [*path]
|
121
|
-
|
122
121
|
key = path.first.to_s
|
122
|
+
|
123
|
+
if key =~ /^([^\]]+)\[(\d+)\]$/
|
124
|
+
key = $1
|
125
|
+
index = $2.to_i
|
126
|
+
end
|
127
|
+
|
123
128
|
rest = path[1..-1]
|
124
129
|
|
125
130
|
# stringify the key we're processing
|
@@ -135,13 +140,11 @@ class Hash
|
|
135
140
|
end
|
136
141
|
else
|
137
142
|
if self[key].is_a?(Array) and self[key].first.is_a?(Hash)
|
138
|
-
# set only on specific array
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
}) unless self[key][i].nil?
|
144
|
-
end
|
143
|
+
# set only on a specific array item
|
144
|
+
# key will be in the form key[0], key[1], key[n]
|
145
|
+
#
|
146
|
+
if not index.nil?
|
147
|
+
self[key][index].rset(rest, value, options) unless self[key][index].nil?
|
145
148
|
|
146
149
|
# set path on all array items
|
147
150
|
else
|
@@ -219,29 +222,34 @@ class Hash
|
|
219
222
|
}), &block)
|
220
223
|
|
221
224
|
elsif v.is_a?(Array) and v.first.is_a?(Hash)
|
222
|
-
v.
|
223
|
-
if
|
225
|
+
v.each.with_index do |vv,i|
|
226
|
+
if vv.is_a?(Hash)
|
227
|
+
pp = path[0..-2]+["#{path[-1]}[#{i}]"]
|
228
|
+
|
224
229
|
if options[:intermediate] === true
|
225
|
-
yield(k.to_s,
|
230
|
+
yield(k.to_s, vv, pp, dhm)
|
226
231
|
end
|
227
232
|
|
228
|
-
|
229
|
-
:path =>
|
230
|
-
:index => i,
|
233
|
+
vv.each_recurse(options.merge({
|
234
|
+
:path => pp,
|
231
235
|
:dhm => dhm
|
232
236
|
}), &block)
|
233
237
|
end
|
234
238
|
end
|
235
239
|
|
236
240
|
else
|
237
|
-
|
241
|
+
yield(k.to_s, v, path, dhm)
|
238
242
|
end
|
239
243
|
|
240
244
|
h
|
241
245
|
end
|
242
246
|
|
243
|
-
|
244
|
-
|
247
|
+
if options[:dhm].nil?
|
248
|
+
# apply any pending operations accumulated from the inject() loop and return
|
249
|
+
return dhm.apply()
|
250
|
+
else
|
251
|
+
return rv
|
252
|
+
end
|
245
253
|
end
|
246
254
|
|
247
255
|
def compact()
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.34
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
40
|
version: '0'
|
41
41
|
requirements: []
|
42
42
|
rubyforge_project:
|
43
|
-
rubygems_version: 1.8.
|
43
|
+
rubygems_version: 1.8.11
|
44
44
|
signing_key:
|
45
45
|
specification_version: 3
|
46
46
|
summary: Useful utility methods for working with Ruby hashes
|