From: ES Date: 2005-05-16T05:42:47+09:00 Subject: Re: help about yaml/eval code Le 15/5/2005, "dave" a �crit: > > >ddir = ENV['DOCUMENT_ROOT'] + '/data' > >Find.find(ddir){|f| > if (f =~ /.yml$/) # has yml extention > eval "#{File.basename(f.delete('.yml'))} = YAML.load(File.new(f))" > else > next > end >} > >I serched on ruby-talk but i did not find any solution. > >How this code can be written (or re-written)? I am not sure if I should be answering since I seem to be even denser than usual but to me it looks like you are trying to assign the contents of a file to a variable named after the file, is that right? This might work: files = {} Find.find("#{ENV[DOCUMENT_ROOT]}/data") do |path| if path =~ /.yml$/ File.open path do |file| # #eval or #instance_variable_set should work here, too files[file.basename[0...-4]] = YAML.load file end end end >tnx. E -- template void quack(duck& d) { d.quack(); }