From: Stuart Clarke Date: 2009-05-08T22:58:18+09:00 Subject: Re: Adding data to text file variables 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? > 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? Many thanks Jes炭s Gabriel y Gal叩n wrote: > On Thu, May 7, 2009 at 4:57 PM, Stuart Clarke > wrote: >> predefined text file containing some data and three variables has each >> I these will updated (like find and replace) using the Ruby GUI. > This sounds like templating. Take a look at some templating engines > like ERB. You can have a file like this: > > blah, blah > <%= variableA %> > xxxx > <%= variableB %> > yyy > > and your program can do: > > require 'erb' > > variableA = "something" > variableB = "other thing" > > template = ERB.new(File.read("template.erb"), nil, "%<>") > File.open("result.txt", "w") do |f| > f.puts template.result(binding) > end > > If you just need simple search and replace, maybe a simpler approach > is enough, but I like the power of templating like this. > > Hope this helps, > > Jesus. -- Posted via http://www.ruby-forum.com/.