Skip to content

Instantly share code, notes, and snippets.

@beatak
Created December 13, 2018 21:45
Show Gist options
  • Save beatak/ee420a513d0a24eb0545b1123de5c573 to your computer and use it in GitHub Desktop.
Save beatak/ee420a513d0a24eb0545b1123de5c573 to your computer and use it in GitHub Desktop.
% irb
# Newer hash literal
2.3.5 :001 > h1 = { name: 'hash1' }
=> {:name=>"hash1"}
2.3.5 :002 > h1['name']
=> nil
2.3.5 :003 > h1[:name]
=> "hash1"
# Old-school hash literal
2.3.5 :004 > h2 = { :name => 'hash2' }
=> {:name=>"hello"}
2.3.5 :005 > h2['name']
=> nil
2.3.5 :006 > h2[:name]
=> "hash2"
# JSON
2.3.5 :007 > require 'json'
=> true
2.3.5 :008 > h3 = JSON.parse '{"name":"hash3"}'
=> {:name=>"hash3"}
2.3.5 :009 > h3['name']
=> "hash3"
2.3.5 :010 > h3[:name]
=> nil
# Then mix…
2.3.5 :011 > h4 = JSON.parse('{"name":"hash4"}').merge({ name: 'symobled hash4'})
=> {"name"=>"hash4", :name=>"symobled hash4"}
2.3.5 :012 > JSON.parse(h4.to_json)
=> {"name"=>"symobled hash4"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment