Created
August 16, 2024 18:04
-
-
Save ewalk153/13380f6603e1cf41473a0949f8a70979 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):002> h = {}.compare_by_identity | |
=> {} | |
irb(main):003> h['a'] =3 | |
=> 3 | |
irb(main):004> h['a'] =5 | |
=> 5 | |
irb(main):005> h | |
=> {"a"=>3, "a"=>5} | |
irb(main):006> h[:a] = 1 | |
=> 1 | |
irb(main):007> h[:a] = 2 | |
=> 2 | |
irb(main):008> h | |
=> {"a"=>3, "a"=>5, :a=>2} | |
irb(main):009> h["a"] | |
=> nil | |
irb(main):011> x = h.first[0] | |
=> "a" | |
irb(main):012> h[x] | |
=> 3 | |
irb(main):014* h.each do |k,v| | |
irb(main):015* puts "#{k} - #{h[k]}" | |
irb(main):016> end | |
a - 3 | |
a - 5 | |
a - 2 | |
=> {"a"=>3, "a"=>5, :a=>2} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment