class SleepingKingStudios::Tools::Toolbox::ConstantMap

Provides an enumerable interface for defining a group of constants.

Attributes

all[R]

@return [Hash] The defined constants.

to_h[R]

@return [Hash] The defined constants.

Public Class Methods

new(constants) click to toggle source

@param constants [Hash] The constants to define.

Calls superclass method
# File lib/sleeping_king_studios/tools/toolbox/constant_map.rb, line 15
def initialize(constants)
  super()

  @to_h = constants.dup

  constants.each do |const_name, const_value|
    const_set(const_name, const_value)

    define_reader(const_name)
  end
end

Public Instance Methods

freeze() click to toggle source

Freezes the constant map and recursively freezes every constant value using ObjectTools#deep_freeze.

@see ObjectTools#deep_freeze

Calls superclass method
# File lib/sleeping_king_studios/tools/toolbox/constant_map.rb, line 75
def freeze
  super

  tools.hsh.deep_freeze(@to_h)

  self
end

Private Instance Methods

define_reader(const_name) click to toggle source
# File lib/sleeping_king_studios/tools/toolbox/constant_map.rb, line 85
def define_reader(const_name)
  reader_name ||= tools.str.underscore(const_name.to_s).intern

  define_singleton_method(reader_name) { const_get const_name }
end
tools() click to toggle source
# File lib/sleeping_king_studios/tools/toolbox/constant_map.rb, line 91
def tools
  ::SleepingKingStudios::Tools::Toolbelt.instance
end