Created
November 6, 2008 14:24
-
-
Save semanticart/22590 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
# what is going on with Hash.new([])? | |
lines = [ | |
[1,2], | |
[3,4], | |
[5,6], | |
[5,6.5], | |
[7,8] | |
] | |
present = Hash.new([]) | |
lines.map do |item| | |
present[item.first] << item.last | |
"some important value" | |
end | |
# present = {} ?!?!?!?! | |
present = {} | |
lines.map do |item| | |
present[item.first] ||= [] | |
present[item.first] << item.last | |
"some important value" | |
end | |
# present = {5=>[6, 6.5], 1=>[2], 7=>[8], 3=>[4]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment