From: "Thomas B." Date: 2008-10-07T00:59:38+09:00 Subject: Re: Printing varible with quotes around it Jack Smith wrote: > I am trying to print my variable in a puts statment but add quotes > around it. > > This works but does not put quotes around my text: > z = "This is my text" > puts z > > I have tried > > puts %Q!z! > and > puts '"#{z}"' > > but I can't seem to get my text to print out like: > > "This is my text" > > thanks > > John You get this result if you use p instead of puts. But there's also one great thing to remember: what p does is in fact: def p(x) # I skipped the multiple argument variant for simplicity puts x.inspect end The function inspect is also used when irb presents results of last operation after the => sign, so you can also do this with arrays, hashes and all other types of objects, if you want to print them in a nice way, with all dangerous characters escaped and so on. TPR. -- Posted via http://www.ruby-forum.com/.