From: Andrea Fazzi Date: 2006-12-25T19:48:09+09:00 Subject: Re: A problem about replacing a string in a template. Kuang Dong wrote: > File 1: test.tpl > > Hello,#{name}! > > File 2: test.rb > > name = "jack" > f = File.open("test.tpl") > puts f.read > puts "Hello,#{name}" > f.close > > And the result is: > Hello,#{name}! > Hello,jack! > > How to change the "#{name}" to "jack"? > > Use ERB to do templating! File 1: test.tpl Hello, <%= name %>! File 2: test.rb require 'erb' name = "Jack" File.open('test.tpl') { |file| puts ERB.new(file.read).result } Bye. Andrea