Class: HierarchicalConfig::OpenStruct
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- HierarchicalConfig::OpenStruct
- Defined in:
- lib/hierarchical_config.rb
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mid, *args) ⇒ Object
:nodoc:
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/hierarchical_config.rb', line 11 def method_missing( mid, *args ) # :nodoc: mname = mid.id2name len = args.length if mname.chomp!('=') if len != 1 raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1) end modifiable[new_ostruct_member(mname)] = args[0] elsif len == 0 && @table.key?( mid ) @table[mid] else raise NoMethodError, "undefined method `#{mname}' for #{self}", caller(1) end end |
Instance Method Details
#to_hash ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/hierarchical_config.rb', line 26 def to_hash @table.inject({}) do |hash, key_value| key, value = *key_value hash[key] = value.respond_to?( :to_hash ) ? value.to_hash : value hash end end |