beginner's ruby question: how to use erb to output file after binding
- by john
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 another file: "text2.txt"?
thank you!!!