Skip to content

Instantly share code, notes, and snippets.

@juanhiplogiq
Created October 27, 2013 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanhiplogiq/7186105 to your computer and use it in GitHub Desktop.
Save juanhiplogiq/7186105 to your computer and use it in GitHub Desktop.
Alternative hash injection.
@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