---
title: "Create a Hash from an Enumerable (Rails 6.0)"
description: "New method allowing you to create a Hash from an Enumerable:"
canonical: https://oozou.com/til/create-a-hash-from-an-enumerable-rails-6-0-6
locale: en
date: 2020-10-13
topic: ruby-on-rails
---

# Create a Hash from an Enumerable (Rails 6.0)

> New method allowing you to create a Hash from an Enumerable:

Published: 2020-10-13 · Topic: [ruby on rails](https://oozou.com/til-topics/ruby-on-rails) ([markdown](https://oozou.com/til-topics/ruby-on-rails.md))

New method allowing you to create a Hash from an Enumerable:

```ruby
%w(driver owner drivy).index_with(nil)
# => { 'driver' => nil, 'owner' => nil, 'drivy' => nil }

%w(driver owner drivy).index_with { |role| delta_amount_for(role) }
# => { 'driver' => '...', 'owner' => '...', 'drivy' => '...' }
```

---

Contact OOZOU: hello@oozou.com · +66 2544 0000 · https://oozou.com/contact

More for AI agents: https://oozou.com/llms.txt · every page has a markdown twin at its URL plus ".md"
