Method: Nugrant::Bag#initialize

Defined in:
lib/nugrant/bag.rb

#initialize(elements = {}, config = {}) ⇒ Bag

Create a new Bag object which holds key/value pairs. The Bag object inherits from the Hash object, the main differences with a normal Hash are indifferent access (symbol or string) and method access (via method call).

Hash objects in the map are converted to Bag. This ensure proper nesting of functionality.

| Arguments

* `elements`
  The initial elements the bag should be built with it.'
  Must be an object responding to `each` and accepting
  a block with two arguments: `key, value`. Defaults to
  the empty hash.

* `config`
  A Nugrant::Config object or hash passed to Nugrant::Config
  constructor. Used for `key_error` handler.


26
27
28
29
30
31
32
33
34
# File 'lib/nugrant/bag.rb', line 26

def initialize(elements = {}, config = {})
  super()

  @__config = Config::convert(config)

  (elements || {}).each do |key, value|
    self[key] = value
  end
end