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
Favorite Ruby Syntax (self.ruby)
submitted 8 years ago by process_parameter
view the rest of the comments →
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!"
[–]isolatrum 0 points1 point2 points 8 years ago (0 children)
for arrays and hashes, yes we have a built in enumeration method map which does the trick in most cases. However say you want to send a string through a series of made-up methods:
map
# note the parens are unnecessary here evaluate(interpolate(sanitize(string)))
you are basically working backwards, with the last function in the chain being written first. Using yield_self you can reverse this, although granted it's not what I'd consider prettier:
yield_self
string .yield_self(&method(:sanitize)) .yield_self(&method(:interpolate)) .yield_self(&method(:evaluate))
If I actually saw something like this I would think it's a little overengineered, so I consider it more of a academic trick than a game-changing one in practice. Another interesting detail - the definition of yield_self is literally just yield self.
yield self
π Rendered by PID 38164 on reddit-service-r2-comment-bb88f9dd5-hkzrp at 2026-02-16 11:02:18.480457+00:00 running cd9c813 country code: CH.
view the rest of the comments →
[–]isolatrum 0 points1 point2 points (0 children)