From: Jenny Purcell Date: 2007-07-23T01:14:59+09:00 Subject: Re: extra text in puts command On Sun, 22 Jul 2007 15:14:00 +0900, Sharon Phillips wrote: >On 22/07/2007, at 3:45 PM, Jenny Purcell wrote: >> Do I need to escape the slash "/" and "pp" in some way? >> >> Jenny > >Hi Jenny, > >you could try >puts CSV.generate_line(["pp#{pole_new[j]}", horse_name[j], ... , "# >{position[j]}/#{count}" ] ) > >By using double quotes, Ruby checks the string first for special >sequences which get evaluated first and the results inserted into the >string. To 'drop in' a value we can surround it with #{ and }. >Example >puts "2 + 3 = #{2+3}" >or >puts "pp#{pole_new[j]}" >In these examples, the expression between #{ and } is evaluated first >and the result substituted, so #{2+3} is replaced with the result, 5. >'/' does not require escaping, but '\' does. To escape '\' just put >another before it "\\" > >Note that using single quotes makes Ruby take the string 'as is'. It >ignores any escape chars and #{...} expressions. >puts "2 + 3 = #{2+3}" # double quotes > > 2 + 3 = 5 >puts '2 + 3 = #{2+3}' # single quotes > > 2 + 3 = #{2+3} > >I hope this makes sense... > >Cheers, >Dave > Thank for the help, it worked very well, although I did decide to change it to look like 1(12) instead of 1/12 (it was treating the latter as a date). But, the quotes and the pound sign worked like a charm! Also, I looked over where you converted my code over to OO, and I can sort of follow what's happening, but, not well enough to expand the program any further (it's probably only about half written). So, I'll keep what you've done as a reference, but, I'm going to continue to write it in a procedural style, until it's "done-done". Then I can decide if I have the extra time to invest in trying to grok OO style. Jenny