From: "Jesús Gabriel y Galán" Date: 2009-05-11T04:49:20+09:00 Subject: Re: Adding data to text file variables On Fri, May 8, 2009 at 3:58 PM, Stuart Clarke wrote: > Thanks for your prompt reply. Can I run over a few bits of the code you > send across? > >> template = ERB.new(File.read("template.erb"), nil, "%<>") > > What does the above line of code, do? What is the erb file? Reads the file template.erb, and creates an ERB template. The file can be something like I wrote in the first email: >> blah, blah >> <%= variableA %> >> xxxx >> <%= variableB %> >> yyy >> > > File.open("result.txt", "w") do |f| >>    f.puts template.result(binding) >> end > > This makes no reference to the variables, so how are they written to the > text file? ERB receives a binding to evaluate the template. In this case we are calling the binding method in the same scope as the local variables, meaning that any code evaluated with that binding can use them. Jesus.