Why can't I write variables to a file?

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

On Thu, Jun 4, 2009 at 3:35 PM, Graham [email protected]
wrote:

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 #{<variable/method call>} to tell ruby to
execute code and not interpret the text as text.

Andrew T.
http://ramblingsonrails.com

http://MyMvelope.com - The SIMPLE way to manage your savings

Thanks Andrew! Works fine. (I’m too use to Perl where you just provide
the
variable).

“Andrew T.” [email protected] wrote in message
news:[email protected]
On Thu, Jun 4, 2009 at 3:35 PM, Graham [email protected]
wrote:

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 #{<variable/method call>} to tell ruby to
execute code and not interpret the text as text.

Andrew T.
http://ramblingsonrails.com

http://MyMvelope.com - The SIMPLE way to manage your savings