Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!tudelft.nl!txtfeed1.tudelft.nl!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!talisker.lacave.net!lacave.net!not-for-mail From: 7stud -- Newsgroups: comp.lang.ruby Subject: Re: Can I Add quotes to values in a array? or include quotes.. Date: Tue, 26 Apr 2011 12:26:50 -0500 Organization: Service de news de lacave.net Lines: 74 Message-ID: References: <1564dc8f34b4628de596a92894889790@ruby-forum.com> NNTP-Posting-Host: bristol.highgroove.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: talisker.lacave.net 1303838862 39179 65.111.164.187 (26 Apr 2011 17:27:42 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Tue, 26 Apr 2011 17:27:42 +0000 (UTC) In-Reply-To: <1564dc8f34b4628de596a92894889790@ruby-forum.com> X-Received-From: This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway X-Mail-Count: 382212 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:3525 Richard Sandoval wrote in post #995007: > When I puts that yaml file for that application field, I get App1,App2. > How can I add quotes to each application. I'd like my output to be > "App1,App2" which includes the quotes in the output > In Ruby, two of the String constructors are ' ' and " ". So if you create a string like this: str = 'hello' and write: puts str then the output will be: hello Now, what if you want str to start with a dash and end with a dash? How would you do that? Like this: str = '-hello-' puts str and the output will be: -hello- Similarly, if you want the string to start with a double quote and end with a double quote, then include a double quote before the 'h' and after the 'o': str = '"hello"' puts str and the output will be: "hello" But what if you try: str = ""hello"" puts str ruby first sees this: str = "" which sets str to a blank string. Then the rest of the line confuses ruby, so ruby stops everything and gives you an error. Sometimes mixing single quotes and double quotes gets confusing, so ruby also provides two other string constructors: %q and %Q. The lower case 'q' is the same as single quotes, and the uppercase 'Q' is the same as double quotes: str = %q{"hello \n world"} puts str --output:-- "hello \n world" str = %Q{"hello \n world"} puts str --output:-- "hello world" -- Posted via http://www.ruby-forum.com/.