Guest User

Untitled

a guest
Aug 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. p={'x': 1534804991, 'y': 0.1}
  2.  
  3. p={:x=>1534804991, :y=>0.1}
  4.  
  5. p.gsub(''x'',':x=>')
  6. p.gsub("'x'",":x=>")
  7. p.sub!(w/xw/, ":x=>")
  8.  
  9. hash = {'x': 1534804991, 'y': 0.1}
  10. p hash.transform_keys(&:to_sym) # {:x=>1534804991, :y=>0.1}
  11.  
  12. hash.each_with_object({}) { |(k, v), h| h[k] = v }
  13.  
  14. p = File.read('xxx.json')
  15. # => "{'x': 1534804991, 'y': 0.1}"
  16.  
  17. puts p
  18. # => {'x': 1534804991, 'y': 0.1}
  19.  
  20. puts p.gsub(/'(w+)': /, ':1=>')
  21. # => {:x=>1534804991, :y=>0.1}
Add Comment
Please, Sign In to add comment