Class: Config::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/config.rb

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Configuration

If block given, greate all instance variables

Yields:

  • (_self)

Yield Parameters:



51
52
53
54
# File 'lib/config.rb', line 51

def initialize
  yield(self) if block_given?
  return self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Sets any un set instance variables



56
57
58
59
60
61
62
63
64
65
# File 'lib/config.rb', line 56

def method_missing(method, *args, &block)
  attr_name = method.to_s.gsub("=","")
  self.class.send(:attr_accessor, attr_name) ## Ensure accesor is set
  # ensure correct behavior if accesor was not set, hence method was missing
  if self.instance_variable_defined?("@#{attr_name}")
    self.instance_variable_get("@#{attr_name}")
  else
    self.instance_variable_set("@#{attr_name}", args.first)
  end
end