ruby - Alternatives to convert a array to a hash using same keys and values -


i want convert:

[:one, :two, :three] 

to:

{one: :one, two: :two, three: three} 

so far i'm using this:

hash[[:basic, :silver, :gold, :platinum].map { |e| [e, e] }] 

but know if it's possible other way?

this use in rails enum definition in model, save values strings in db.

i admit hangup: given choice, prefer constructing hashes scratch rather creating array , converting hash.

[:one, :two, :three].each_with_object({}) { |e,h| h[e]=e }   #=> {:one=>:one, :two=>:two, :three=>:three} 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -