# Arbitrary depth access yml with method\_missing help

**URL:** <https://www.ruby-forum.com/t/arbitrary-depth-access-yml-with-method-missing-help/152093>\
**Category:** Ruby\
**Created:** [October 30, 2008, 3:51am UTC](https://www.ruby-forum.com/t/arbitrary-depth-access-yml-with-method-missing-help/152093 "2008-10-30T03:51:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![2tcreative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/a3d4f5/32.png) [@2tcreative](https://www.ruby-forum.com/u/2tcreative)\
**Post date:** [October 30, 2008, 3:51am UTC](https://www.ruby-forum.com/t/arbitrary-depth-access-yml-with-method-missing-help/152093/1 "2008-10-30T03:51:44Z")

</div>

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
