Class: WebPackage::ConfigurationHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/web_package/configuration_hash.rb

Overview

A Hash class with configurable dot-methods (accessors).

Instance Method Summary collapse

Constructor Details

#initialize(accessor_names, &block) ⇒ ConfigurationHash

Returns a new instance of ConfigurationHash.



4
5
6
7
# File 'lib/web_package/configuration_hash.rb', line 4

def initialize(accessor_names, &block)
  self.accessors = [*accessor_names]
  super(&block)
end

Instance Method Details

#accessors=(method_names) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/web_package/configuration_hash.rb', line 9

def accessors=(method_names)
  self.class.class_eval do
    method_names.map(&:to_sym).each do |method_name|
      define_method(method_name) { self[method_name] }
      define_method("#{method_name}=") { |value| self[method_name] = value }
    end
  end
end