From: Andrea Maschio Date: 2007-02-02T08:12:01+09:00 Subject: Re: Parsing text files with dynamic contents ------=_Part_21675_11960012.1170371516654 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Well, that seems to be exactly what i was looking for, thank you Brian. So i think i could give erb every line to parse or make him parse the entire file before output it on the screen, right? now, i've got a little question more. Let's say i have a class, Foo, who calls a method of another class to print the output. For example class Foo @w @myvar def initialize w=Writer.new end def print_something w.put_on_screen(1) end end class Writer def put_on_screen(number) file=File.open("./screens/screen#{number}","r") file.each do |line| e=ERB.new(line) puts e.result end end end in the txt file, how can i make visible @myvar to print it on the screen? Thanks again 2007/2/1, Brian Candler : > > On Fri, Feb 02, 2007 at 06:35:21AM +0900, Andrea Maschio wrote: > > Let's guess a simple example: i need to parse a text file, wityh > variables > > inside, and then output again the resulting text to a file or to screen. > > > > -------------start example text------------ > > > > hello, it is #{now}, your name is #{name} > > > > > > -------------end example text------------ > > > > variables could be written also $var, or whatever else could be better. > > > > but obviously when i do > > > > file.each do |line| > > puts line #here i need to do something to find the variable and > > output the correct value > > end > > > > How would you ruby experts do the correct parsing to output values > instead > > of the text content? Is there any class available that do this? > > Google for 'erb' and 'eruby' > > -- Andrea Maschio cell. +39 333 2672629 email: andrea.maschio@gmail.com http://www.superandrew.it "The real problem is not whether machines think but whether men do." (B. F. Skinner ) ------=_Part_21675_11960012.1170371516654--