Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1.  
  2. def json_response
  3. json_with_indifferent_access JSON.parse response.body
  4. end
  5.  
  6. def json_with_indifferent_access(json)
  7. traverse_json(json) {|j| j.is_a?(Hash) ? j.with_indifferent_access : j }
  8. end
  9.  
  10. def traverse_json(json, &block)
  11. x = case json
  12. when Hash
  13. json.map { |j| traverse_json j, &block }.to_h
  14. when Array
  15. json.map { |j| traverse_json j, &block }
  16. else
  17. json
  18. end
  19. block.call x
  20. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement