Class NestedMultimap
In: lib/nested_multimap.rb
Parent: Multimap

NestedMultimap allows values to be assoicated with a nested set of keys.

Methods

Public Instance methods

Pushes the given object on to the end of all the containers.

  map = NestedMultimap["a" => [100], "b" => [200, 300]]
  map << 300
  map["a"] #=> [100, 300]
  map["c"] #=> [300]

Retrieves the value object corresponding to the *keys object.

[]=(*args)

Alias for store

Returns a new array populated with all the containers from map including the default.

  map = NestedMultimap.new
  map["a"] = 100
  map["a", "b"] = 101
  map["a"] = 102
  map.containers_with_default   #=> [[100, 101, 102], [100, 102], []]

Calls block once for each key/container in map, passing the key and container to the block as parameters.

  map = NestedMultimap.new
  map["a"] = 100
  map["a", "b"] = 101
  map["a"] = 102
  map["c"] = 200
  map.each_association { |key, container| puts "#{key} is #{container}" }

produces:

  ["a", "b"] is [100, 101, 102]
  "c" is [200]

Calls block for every container in map including the default, passing the container as a parameter.

  map = NestedMultimap.new
  map["a"] = 100
  map["a", "b"] = 101
  map["a"] = 102
  map.each_container_with_default { |container| puts container }

produces:

  [100, 101, 102]
  [100, 102]
  []

Associates the value given by value with multiple key given by keys.

  map = NestedMultimap.new
  map["a"] = 100
  map["a", "b"] = 101
  map["a"] = 102
  map   #=> {"a"=>{"b"=>[100, 101, 102], default => [100, 102]}}

[Validate]