Created
October 27, 2013 18:26
-
-
Save juanhiplogiq/7186105 to your computer and use it in GitHub Desktop.
Alternative hash injection.
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
@array = ["apple" , "orange", "banana"] | |
#Instead of this, | |
@fruit_hash = @array.inject({}) do |hash,fruit| | |
hash[fruit.to_sym] = fruit | |
hash | |
end | |
#How about this | |
@fruit_hash = @array.inject({}) {|hash,fruit| hash.merge(fruit.to_sym => fruit)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment