Class: CrazyDoll::Config::Instance
- Inherits:
-
Object
- Object
- CrazyDoll::Config::Instance
- Defined in:
- lib/crazy_doll/config.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
Instance Method Summary collapse
-
#initialize(owner, config = {}) ⇒ Instance
constructor
A new instance of Instance.
- #register(owner, key, description, value) ⇒ Object
Constructor Details
#initialize(owner, config = {}) ⇒ Instance
Returns a new instance of Instance.
73 74 75 76 77 |
# File 'lib/crazy_doll/config.rb', line 73 def initialize(owner, config={}) @config = config.empty? ? {} : config @owner = owner @config.keys.each { |k| create_key(k) } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/crazy_doll/config.rb', line 102 def method_missing(name, *args, &block) if name.to_s.match(/=$/) and args.size == 1 key = name.to_s.gsub(/=$/,'').to_sym puts "!!! key #{key} missing, but creating !!!" @config[key] = CrazyDoll::Config.parse(@owner, key, 'created by method_missing', args[0]) create_key(key) @config[key] elsif name.to_s.match(/\?$/) and self.respond_to?((k=name.to_s.gsub(/\?$/,''))) puts "!!! method #{name} missing, creating it !!!" self.instance_eval <<-EVAL def #{name} @config[:#{k}] end EVAL send(name) else puts "!!! method #{name} missing !!!" nil end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
72 73 74 |
# File 'lib/crazy_doll/config.rb', line 72 def config @config end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
72 73 74 |
# File 'lib/crazy_doll/config.rb', line 72 def owner @owner end |