From: "滕祥功" Date: 2008-10-30T11:50:42+09:00 Subject: arbitrary depth access yml with method_missing help ------=_Part_1628_28735120.1225335089347 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi All, Say I have a class named *TrackCompany , *I want to recursively get some value from yml, like *TrackCompany.instance.company01.log_file*, I use the methoding missing to implement it, so currently it will not recursively call method_missing, can anybody help? the yml defined : ========= yml begin ======== tracks: track01: #track name company01: #company name default_run: true log_file: D:\logfile.log ========= yml end =========== and I code the class to get value from it, like : ======== code begin === require 'singleton' require 'yaml' class TrackCompanyConfig include Singleton def initialize @file_path = "./track_company_config.yml" if File.exists?(@file_path) @configs = YAML.load_file(@file_path)["tracks"] else raise "Default config file missing exception, ./track_company_config.yml missing!" end end def method_missing method_sym,*args method_sym = method_sym.to_s if @configs[method_sym].is_a?(Hash) p "then come to next level" @configs = @configs[method_sym] # it just run once, how to make it run recursively? else value = @configs[method_sym] @configs = YAML.load_file(@file_path)["tracks"] value end end end end ===== code end ===== Thanks. Tim ------=_Part_1628_28735120.1225335089347--