beginner's ruby question: how to use erb to output file after binding

Posted by john on Stack Overflow See other posts from Stack Overflow or by john
Published on 2010-06-03T20:21:17Z Indexed on 2010/06/03 20:24 UTC
Read the original article Hit count: 364

Filed under:
|
|

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!!!

© Stack Overflow or respective owner

Related posts about ruby

Related posts about template