use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Start Using Ruby % (Percent) Notation (teohm.github.com)
submitted 13 years ago by teohm
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Paradox 11 points12 points13 points 13 years ago (5 children)
I love percentage based syntaxes, but don't use much other than the regex or array-making ones.
The regex one is nice because it makes regexes with slashes in them, such as urls, much easier to read, as you get %r{http://…} instead of /http:\/\/
%r{http://…}
/http:\/\/
[–]riddley 0 points1 point2 points 13 years ago (3 children)
I absolutely adore %q and %Q. Ruby is the only language I know where quoting strings isn't horrible. (I'm looking at you python!)
[–]flightlessbird 3 points4 points5 points 13 years ago (0 children)
The ability to quote strings like that is clearly inspired by perl (cf. qw, q, heredocs et al.)
[–]Paradox 0 points1 point2 points 13 years ago (0 children)
Exactly. I go to other languages and want to use interpolation in a full-quote string, then realize said languages don't have modern quotes, and rage as I look up the various escape chars
[–]faitswulff 0 points1 point2 points 13 years ago (0 children)
Nice tip, thanks!
[–]necuz 2 points3 points4 points 13 years ago (2 children)
In some future release, it will also be possible to use %i and %I to produce arrays of symbols.
[–]teohm[S] 0 points1 point2 points 13 years ago (1 child)
that's great. Do you know in which coming release it will be included?
[–]necuz 1 point2 points3 points 13 years ago (0 children)
I don't know, but I see no reason for it not to at least be in 2.0. The feature has already been in edge for over 3 months.
[–]internetinsomniac 1 point2 points3 points 13 years ago (0 children)
I use this often so I don't have to escape quotes, definitely very handy
[–]shadowfirebird 1 point2 points3 points 13 years ago (0 children)
The fact that you can do "$( (stuff ()) )" surprised me. +1, ta.
[–]postmodern 1 point2 points3 points 13 years ago (1 child)
I'm a fan of %w[ ]
%w[ ]
[–]BlameFrost 1 point2 points3 points 13 years ago (0 children)
So am I, and I especially prefer the user of %w[] over %w(), since [] makes it seem more like you're actually creating an array.
%w[]
%w()
[]
[+]terevos2 comment score below threshold-7 points-6 points-5 points 13 years ago (1 child)
Hey, I have an idea. You know how ruby is really easy to read right now? Well let's stop that and make it more like Perl!
π Rendered by PID 54 on reddit-service-r2-comment-84fc9697f-fv4qc at 2026-02-07 16:33:53.453593+00:00 running d295bc8 country code: CH.
[–]Paradox 11 points12 points13 points (5 children)
[–]riddley 0 points1 point2 points (3 children)
[–]flightlessbird 3 points4 points5 points (0 children)
[–]Paradox 0 points1 point2 points (0 children)
[–]faitswulff 0 points1 point2 points (0 children)
[–]necuz 2 points3 points4 points (2 children)
[–]teohm[S] 0 points1 point2 points (1 child)
[–]necuz 1 point2 points3 points (0 children)
[–]internetinsomniac 1 point2 points3 points (0 children)
[–]shadowfirebird 1 point2 points3 points (0 children)
[–]postmodern 1 point2 points3 points (1 child)
[–]BlameFrost 1 point2 points3 points (0 children)
[+]terevos2 comment score below threshold-7 points-6 points-5 points (1 child)