Help about yaml/eval code

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)?

tnx.

···

--

here are more things in heaven and earth,

horatio, than are dreamt of in your philosophy.

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

···

Le 15/5/2005, "dave" <dave.m@email.it> a écrit:

--
template<typename duck>
void quack(duck& d) { d.quack(); }

files[file.basename[0...-4]] = YAML.load file

it sounds good, tnx again.

···

--

here are more things in heaven and earth,

horatio, than are dreamt of in your philosophy.