Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A very small Ruby gem to manage multi-level default hashes.
branch: master

This branch is 2 commits behind cespare:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
Gemfile
README.md
Rakefile
deep_hash.gemspec

README.md

deep_hash

deep_hash is a Ruby gem that provides ways to deal with multi-level default hashes.

Usage

Right now the only functionality is to create such a hash. This is useful if you use multi-dimensional default hashes a lot. For example, multi-dimensional tables of counts (defaulting to 0) are often useful.

require "deep_hash"

h = Hash.deep(0) # is equivalent to
h = {}

h = Hash.deep(2) # is equivalent to
h = Hash.new { |k1, v1| k1[v1] = Hash.new { |k2, v2| k2[v2] = {} } }

h = Hash.deep(0) { "foobar" } # is equivalent to
h = Hash.new { |k, v| k[v] = "foobar" }

h = Hash.deep(1) { 0 } # is equivalent to
h = Hash.new { |k1, v1| k1[v1] = Hash.new { |k2, v2| k2[v2] = 0 } }

Installation

gem install deep_hash
Something went wrong with that request. Please try again.