Class: Rad::Config

Inherits:
Object show all
Defined in:
lib/rad/environment/_config.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Config

Returns a new instance of Config.



4
5
6
7
8
# File 'lib/rad/environment/_config.rb', line 4

def initialize hash = {}
  hash.each do |k, v|
    instance_variable_set :"@#{k}", v
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object (protected)



20
21
22
23
24
25
26
# File 'lib/rad/environment/_config.rb', line 20

def method_missing m, *args
  if m =~ /=$/
    instance_variable_set :"@#{m[0..-2]}", args.first
  else
    instance_variable_get :"@#{m}"
  end
end

Instance Method Details

#deep_cloneObject Also known as: clone



10
11
12
13
14
15
16
# File 'lib/rad/environment/_config.rb', line 10

def deep_clone
  clone = Rad::Config.new
  instance_variable_names.each do |k|
    clone.instance_variable_set k, instance_variable_get(k).deep_clone
  end
  clone
end

#subsetObject



2
# File 'lib/rad/environment/_config.rb', line 2

def subset; raise "you probably mistuped, it's config, not hash" end