r/learnruby • u/tourn Intermediate • Sep 22 '14
Ruby Koans question
So I have never done the Ruby Koans. I decided why not lets do this maybe I'll learn some things I didn't know or at least get some practice to solidify what I already know. Now I already know that
hash=Hash.new("cat") creates a default if a key/value isn't explicitly given.
What I don't get is why:
hash = Hash.new([])
hash[:one] << "uno"
hash[:two] << "dos" creates an array with both values in both key bindings.
3
Upvotes
View all comments
Show parent comment
1
u/tourn Intermediate Sep 23 '14 edited Sep 23 '14
Ah ok so like using a pointer as a default. If you
Would that still use the pointer or would it be a separate hash pair
Edit: never mind just tried it in irb. Interesting how the one and two key show the pointer to the array but adding in a key called three value tres is seperate and the only thing in the hash if you puts the hash.