Skip to content

Instantly share code, notes, and snippets.

@KamilLelonek
Created November 20, 2014 04:50
Show Gist options
  • Save KamilLelonek/118a8978e2357e4cd1f6 to your computer and use it in GitHub Desktop.
Save KamilLelonek/118a8978e2357e4cd1f6 to your computer and use it in GitHub Desktop.
Ruby hash quirks - part 2
[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