Created
November 20, 2014 04:50
-
-
Save KamilLelonek/118a8978e2357e4cd1f6 to your computer and use it in GitHub Desktop.
Ruby hash quirks - part 2
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
[1] (pry) main: 0> default_array = []; | |
[2] (pry) main: 0> my_hash = Hash.new default_array; | |
[3] (pry) main: 0> my_hash[:hobbies] << 'dancing'; | |
[4] (pry) main: 0> my_hash[:skills] << 'php'; | |
[5] (pry) main: 0> my_hash[:hobbies] == my_hash[:skills] | |
=> true | |
[6] (pry) main: 0> my_hash[:hobbies] == default_array | |
=> true | |
[7] (pry) main: 0> default_array | |
=> ["dancing", "php"] | |
[8] (pry) main: 0> default_array.object_id | |
=> 70163812238500 | |
[9] (pry) main: 0> my_hash[:hobbies].object_id | |
=> 70163812238500 | |
[10] (pry) main: 0> my_hash[:some_random_key].object_id | |
=> 70163812238500 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment