Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def json_response
- json_with_indifferent_access JSON.parse response.body
- end
- def json_with_indifferent_access(json)
- traverse_json(json) {|j| j.is_a?(Hash) ? j.with_indifferent_access : j }
- end
- def traverse_json(json, &block)
- x = case json
- when Hash
- json.map { |j| traverse_json j, &block }.to_h
- when Array
- json.map { |j| traverse_json j, &block }
- else
- json
- end
- block.call x
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement