Hi, I got the following example:
require 'erb'
names = []
names.push( { 'first' => "Jack", 'last' => "Herrington" } )
names.push( { 'first' => "LoriLi", 'last' => "Herrington" } )
names.push( { 'first' => "Megan", 'last' => "Herrington" } )
myname = "John Smith"
File.open( ARGV[0] ) { |fh|
erb = ERB.new( fh.read )
print erb.result( binding )
accompanied by
text.txt
<% name = "Jack" %>
Hello <%= name %>
<% names.each { |name| %>
Hello <%= name[ 'first' ] %> <%= name[ 'last' ] %>
<% } %>
hi, my name is <%= myname %>
}
it prints nicely to screen.
what is the simplest way to output to another file: "text2.txt" instead of to the screen?
I know this is really a piece of cake for most of you experienced ruby masters, but for me who just picked up a Beginning Ruby from Novice...it's challenging now...but I want to use the code for real life purpose...
thank you!!!