---
title: "Hashtable Tingkat Menengah yang Terbentuk Otomatis di Ruby"
description: "Semua hashtable tingkat menengah akan dibuat secara otomatis"
canonical: https://oozou.com/til/automagical-intermediate-level-hashtables-in-ruby-62
locale: id
date: 2020-10-13
topic: ruby
---

# Hashtable Tingkat Menengah yang Terbentuk Otomatis di Ruby

> Semua hashtable tingkat menengah akan dibuat secara otomatis

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

Semua hashtable tingkat menengah akan dibuat secara otomatis

```ruby
def autovivifying_hash
   Hash.new {|ht,k| ht[k] = autovivifying_hash}
end
```

### Penggunaan

```ruby
response_builder = autovivifying_hash
response_builder['payment']['status'] = 'OK'
response_builder # => {"payment"=>{"status"=>"OK"}
```

---

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

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