Created
July 18, 2017 09:44
-
-
Save igaiga/58abe028148ad1a7235c3c46265c5518 to your computer and use it in GitHub Desktop.
This file contains 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
h = {} | |
["a", "a", "b"].each do |x| | |
h[x] = [] unless h[x] | |
h[x] << x | |
end | |
p h | |
#=> {"a"=>["a", "a"], "b"=>["b"]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
default_proc
で代入すると意図していないところでも勝手に追加されるので、追加するところで代入するとか