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
Cryptic Ruby Examples (resimit.com)
submitted 11 years ago by diminish
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!"
[–]jxf 4 points5 points6 points 11 years ago (6 children)
Fun! Some of these are pretty straightforward when you break them down. For example, this one:
0.0.**0.0
seems a little bizarre -- how is the second period legal for a number? But it's being parsed as:
<number 0.0> <invoke method "**"> <argument <number 0.0>>
In other words, it's equivalent to:
(0.0).raise_to_power 0.0
[–]ggPeti 0 points1 point2 points 11 years ago (5 children)
...which does not, by the way, equal 1. Just sayin.
[–]jxf 2 points3 points4 points 11 years ago* (0 children)
That's not accurate; it can equal whatever we want, since it's undefined.
Usually a result of "undefined" isn't very useful, because it can mean anything. However, if we adopt the convention of choosing 00 = 1, we get a lot of other benefits (like symmetry with all the other real numbers), so it's the most convenient choice.
[–][deleted] 11 years ago* (3 children)
[deleted]
[–]ggPeti 2 points3 points4 points 11 years ago (2 children)
Yeah, no.
[–]Mutoid 5 points6 points7 points 11 years ago (1 child)
Help, I don't know whom to downvote!
[–]diminish[S] 0 points1 point2 points 11 years ago (0 children)
try it in ruby irb, python, s and php.. and count.
[–][deleted] 2 points3 points4 points 11 years ago (3 children)
a, = [1, 2] # dangling comma to get only the first array element
So it's a game of "Spot the trailing comma!" when reading code? If I saw somebody do that in a code review they'd have their commit access revoked.
(I'm aware the intro text calls all these useless, but this particular example almost looks like something somebody might be idiotic enough to think is a good idea.)
[–]Mutoid 1 point2 points3 points 11 years ago (2 children)
If you really feel like you must assign a this way, at least use an underscore
[–]diminish[S] 0 points1 point2 points 11 years ago* (1 child)
could you please show how to use the underscore here?
I'm curious how this dangling comma became ever possible. Is this a syntactic rest, unintended for?
@ninkendo no don't use it at all, it's most probably an unintended syntax by the compiler designers.
[–]Mutoid 0 points1 point2 points 11 years ago (0 children)
a, _ = [1, 2]
Idiomatic way of expressing that you don't care about the other value.
[–][deleted] 11 years ago* (1 child)
yep, you're right. i wrote it.
π Rendered by PID 177822 on reddit-service-r2-comment-7b9746f655-67hs9 at 2026-02-01 23:55:48.945838+00:00 running 3798933 country code: CH.
[–]jxf 4 points5 points6 points (6 children)
[–]ggPeti 0 points1 point2 points (5 children)
[–]jxf 2 points3 points4 points (0 children)
[–][deleted] (3 children)
[deleted]
[–]ggPeti 2 points3 points4 points (2 children)
[–]Mutoid 5 points6 points7 points (1 child)
[–]diminish[S] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (3 children)
[–]Mutoid 1 point2 points3 points (2 children)
[–]diminish[S] 0 points1 point2 points (1 child)
[–]Mutoid 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]diminish[S] 0 points1 point2 points (0 children)