Module: Rlyeh::Settings::ClassMethods

Defined in:
lib/rlyeh/settings.rb

Instance Method Summary collapse

Instance Method Details

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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rlyeh/settings.rb', line 12

def set(option, value = nil, &block)
  if option.respond_to?(:each)
    option.each { |k, v| set k, v }
    return self
  end

  setter = proc { |v| set option, v }
  getter = block ? block : proc { value }

  Rlyeh::Utils.singleton_class(self).class_eval do
    define_method "#{option}=", &setter if setter
    define_method "#{option}", &getter if getter
    class_eval "def #{option}?; !!#{option}; end" unless method_defined?("#{option}?")
  end
end

#settingsObject



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

def settings
  self
end