From: RichardOnRails Date: 2011-05-12T02:51:42+09:00 Subject: Re: Must be my bug, but it looks like Ruby's could it be? On May 9, 3:54 pm, 7stud -- wrote: > RichardOnRails wrote in post #997471: > > > > > > > > > > > On Apr 30, 6:06pm, 7stud -- wrote: > >> > two hashes in this case, which represents the two pseudo-hashes in the > > >> lol. You are using the % shortcut for %Q and you are using [] as the > >> delimiter. I have only one thing to say: horrible code writing. > > >> -- > >> Posted viahttp://www.ruby-forum.com/. > > > Hi 7Stud, > > > Thanks for your response.  As I mentioned to Mike, I had more serious > > things to work on last > > week; hence, my belated response. > > >>> puts %[%d\t%s => %s] % [num+=1, key, value] > > vs. > >> puts "%d\t%s => %s" % [num+=1, key, val] > > > I used %[...] instead of "..." because I often want to include > > embedded double-quotes in my strings > > I'm not sure which 'strings' you are talking about?  key? val?  In that > case, it doesn't matter what is inside key or val: > > key = 'He said, "Hi".' > result = "%s" % key > puts result > > --output:-- > He said, "Hi". > > Note that the substitution is not equivalent to writing: > > result = "He said, "Hi"." > > ..which will not parse correctly. > > If you are talking about the string on the left, then you need to alter > your quoting regimen depending on the specific situation--do not use a > one size fits all approach.  That will just make your code hard to > decipher.  And after trying to decipher your code, I would suggest that > NOBODY ever use the % shortcut--either use %q or %Q.  Code clarity is > much more important than saving one character while typing. > >  and believe my delimiting > > > approach is clearer since I don't have to escape double-quotes. > > Nevertheless, I'm mindful of the ancient adage, de gustibus non est > > disputandum. > > > As I also mentioned to Mike,  I now realize that my parsing routine > > produced errors in in my control data.  Rather than trying to correct > > my amateurish code,  I'm going to study one of Ruby Design Patterns > > for application to this problems. > > > Best wishes, > > Richard > > -- > Posted viahttp://www.ruby-forum.com/. Hi 7Stud, Thanks for taking the trouble press the case that %[...] is less clear than including the explicit q/Q > I would suggest that NOBODY ever use the % shortcut--either use %q or %Q. You may be correct that nobody uses this shortcut. However, AFAIK, Matz implemented the shortcut. In my mind, that weighs more heavily than the proportion of people that use it. Further more, it helps avoid having to remember which of q/Q corresponds to which quote mark. Finally, when I post a question here, I presume that the people who'll respond are Ruby experts who won't be troubled by my use of the shortcut. In any case, I've moved on to another idea, namely using "Design Patterns in Ruby" to parse user-input rather than my convoluted code. Of course, I ran into another problem. I hope you'll be interested in looking at my latest puzzle at http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/d1af38232e963ed6# Best wishes, Richard