Try this:
def hash_with_default_hash
Hash.new { |hash, key| hash[key] = hash_with_default_hash }
end
a = hash_with_default_hash
If the key doesn't exist, then the result of the block will be used as the default value. In this case, the default value is also a hash which uses hashes as its default values.