[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

arbitrary depth access yml with method_missing help

???

10/30/2008 2:51:00 AM

[Note: parts of this message were removed to make it a legal post.]

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

1 Answer

poisoned rose

11/2/2010 9:16:00 PM

0

"who?" <yourimageunreels@sbcglobal.net> wrote:

> > > Let's talk about ATMP. It was better cause it had slide and Clapton
> > > on it. :-)
> >
> > Still repeatedly trolling about issues you claim don't matter much to
> > you, eh?
>
> Why is it you think ATMP is his best album? All of his albums
> have some good songs.

Because I don't think all of his albums have some good songs.