Skip to content

Commit 9174c4a

Browse files
author
Kyle Decot
committed
Shorter syntax for process
1 parent cddc8ab commit 9174c4a

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

lib/kmdata.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,26 @@ def http
3131
# Takes JSON and converts it into a OpenStruct representation. This method
3232
# is recursive so it's somewhat hard to tell what's going on sometimes...
3333
def process(json)
34-
3534
# If the current json is an array then we need to loop through each
3635
# element and process it and add it to the newly created array
3736

3837
if json.is_a? Array
39-
result = json.map do |element|
38+
json.map do |element|
4039
process(element)
4140
end
4241

4342
# If the current json is a hash then we need to created a new hash by
4443
# looping over each of it's keys and processing the values
4544

4645
elsif json.is_a? Hash
47-
json = Hash[json.map{ |key, value| [key,process(value)] }]
48-
result = OpenStruct.new(json)
46+
OpenStruct.new(Hash[json.map{ |key, value| [key,process(value)] }])
4947

5048
# The current json is some kind of primitive so there's nothing to do in
5149
# this case so we'll just return it
5250

5351
else
54-
result = json
52+
json
5553
end
56-
57-
result
5854
end
5955

6056
def path_with_params(path, params)

0 commit comments

Comments
 (0)