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

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

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

laravel - Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id (View: F:\project\resources\views\admin\carousels\index.blade.php) -