Module: Makitzo::Settings

Included in:
Config, World::NamedEntity
Defined in:
lib/makitzo/settings.rb

Overview

mixin providing classes with a settings hash

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



8
9
10
# File 'lib/makitzo/settings.rb', line 8

def [](key)
  read(key)
end

#[]=(key, value) ⇒ Object



12
13
14
# File 'lib/makitzo/settings.rb', line 12

def []=(key, value)
  set(key, value)
end

#memo(key, &block) ⇒ Object



26
27
28
# File 'lib/makitzo/settings.rb', line 26

def memo(key, &block)
  set(key, MemoizedProc.new(&block))
end

#read(key, default = nil) ⇒ Object



16
17
18
19
20
# File 'lib/makitzo/settings.rb', line 16

def read(key, default = nil)
  val = settings[key.to_sym]
  val = val.call if val.respond_to?(:call)
  val.nil? ? default : val
end

#set(key, value = nil, &block) ⇒ Object



22
23
24
# File 'lib/makitzo/settings.rb', line 22

def set(key, value = nil, &block)
  settings[key.to_sym] = block_given? ? block : value
end

#settingsObject



4
5
6
# File 'lib/makitzo/settings.rb', line 4

def settings
  @settings ||= {}
end