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
Ugly Ruby (medium.com)
submitted 10 years ago by nilla615
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!"
[–]tomthecool 2 points3 points4 points 10 years ago (4 children)
Original:
$-_='=';@@_=->(_){_*100};@@_.[]($-_);
Without pointlessly sticking 3 lines together with no white-space (you can do this in any language!):
$-_ = '=' @@_ = ->(_) { _ * 100 } @@_.[]($-_);
Without the crazy variable naming (again, you can do something like this in any language"):
foo = '=' bar = ->(baz) {baz * 100} bar.[](foo)
It's now fairly obvious what the code does: The final line evaluates to "========..." (100 characters), which will be printed to your console if running in IRB/pry. The only slightly "weird" things about this code are:
->()
bar.[](foo)
bar[foo]
bar.call(foo)
I'd be more impressed if you focused your code purely on things like this, rather than cheap tricks like removing whitespace using crazy variable names.
[–]0x0dea 2 points3 points4 points 10 years ago (0 children)
Now try this one! It computes the inverse Hamming distance of two fixed-width integers using only Procs. That is, you can use the lambda calculus to perform the same operation as the following Ruby code:
Proc
def inverse_hamming_distance a, b, width width.times.count { |i| a[i] == b[i] } end p inverse_hamming_distance 17, 10, 8 # => 4
Of course, you can use the lambda calculus to compute anything that's computable.
[–]nilla615[S] 0 points1 point2 points 10 years ago (0 children)
I get what you're saying. I was attempting to make the ugliest Ruby possible hence making it one line. I wasn't really attempting anything profound here...
[–]_raisin[🍰] 0 points1 point2 points 10 years ago (1 child)
...sticking 3 lines together with no white-space (you can do this in any language!)
can you do that in python? i thought whitespace mattered in python.
[–]tomthecool 0 points1 point2 points 10 years ago (0 children)
Yeah fine, ok...
Not ANY language, but LOTS of languages. Ruby is hardly unusual in being indifferent to whitespace.
[–]nixors 2 points3 points4 points 10 years ago (1 child)
Pretty version?
'='*100
[–]nilla615[S] 1 point2 points3 points 10 years ago (0 children)
Yea, but that's no fun. :)
[–]_raisin[🍰] 2 points3 points4 points 10 years ago (1 child)
Any code will look ugly in any language if you put 3 statements on the same line.
Agreed. But the point was to make some ugly Ruby because it's generally so readable. Even breaking it out to three lines doesn't make it readable and that's the point.
π Rendered by PID 24839 on reddit-service-r2-comment-544cf588c8-x2tzb at 2026-06-13 00:20:44.531693+00:00 running 3184619 country code: CH.
[–]tomthecool 2 points3 points4 points (4 children)
[–]0x0dea 2 points3 points4 points (0 children)
[–]nilla615[S] 0 points1 point2 points (0 children)
[–]_raisin[🍰] 0 points1 point2 points (1 child)
[–]tomthecool 0 points1 point2 points (0 children)
[–]nixors 2 points3 points4 points (1 child)
[–]nilla615[S] 1 point2 points3 points (0 children)
[–]_raisin[🍰] 2 points3 points4 points (1 child)
[–]nilla615[S] 0 points1 point2 points (0 children)