From: Graham Date: 2009-06-05T00:20:05+09:00 Subject: Re: Why can't I write variables to a file? Thanks Andrew! Works fine. (I'm too use to Perl where you just provide the variable). "Andrew Timberlake" wrote in message news:62ad3e390906040638o4c690cf4w128339bb992bc93@mail.gmail.com... On Thu, Jun 4, 2009 at 3:35 PM, Graham wrote: > Help please! I'm a Ruby newbie and can't get the variables in the > following > script to write to a file (is it something to do with defining the > variables?). > > # create variables > class Person > attr_accessor :name, :age > end > person_instance = Person.new > person_instance.name = "David" > person_instance.age= "37" > > # write to an HTML file > File.open("test4.html", "w") do |f| > f.puts "

person_instance.name > (person_instance.age), sat at the table

" > end Try .. # write to an HTML file File.open("test4.html", "w") do |f| f.puts "

#{person_instance.name} (#{person_instance.age}), sat at the table

" end Inside of "" you need to use #{} to tell ruby to execute code and not interpret the text as text. Andrew Timberlake http://ramblingsonrails.com http://MyMvelope.com - The SIMPLE way to manage your savings