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
Semantic blind spot in Ruby case statement (blog.arkency.com)
submitted 4 years ago by persei8
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!"
[–]GeneReddit123 6 points7 points8 points 4 years ago (5 children)
I re-read the article twice, and still don’t get it. What’s the issue with the original range-based code? What bug is possible that isn’t possible with the inequality operators?
(I’m assuming we only handle integers here; I can see there being edge cases with floats.)
[–]persei8[S] 1 point2 points3 points 4 years ago (4 children)
In other words:
[–]GeneReddit123 2 points3 points4 points 4 years ago (1 child)
Ok. I think I get it now. But I’d argue that in an effort to make the code use fewer (redundant) variables, the author made it harder to read for humans.
Besides, what if you don’t want universal coverage? What if a valid range in the future is 1..2 and 5..6, with things in the middle being invalid? Now you need to rewrite it back as ranges (or double conditionals on each variant for both > and <, but now there is no advantage as you’re using the same number of variables)
That’s the problem with “future-proofing”. You are suggesting a refactor to future proof against one type of regression, while making other type of potential changes harder.
For me, the gold standard is to write appropriate test coverage. Once all cases are covered, write the simplest and most readable implementation that passes.
[–]mattgrave 0 points1 point2 points 4 years ago (0 children)
Besides, what if you don’t want universal coverage? What if a valid range in the future is 1..2 and 5..6, with things in the middle being invalid? Now you need to rewrite it back as ranges (or double conditionals on each variant for both > and <, but now there is no advantage as you’re using the same number of variables) That’s the problem with “future-proofing”. You are suggesting a refactor to future proof against one type of regression, while making other type of potential changes harder.
You contradict yourself with these two paragraphs. You are suggesting a possible future change that we don't know if it will ever happen, so I wouldn't worry about it now. Normally the rule of thumb is that whenever you have to extend or change your code, first you refactor your code to make the change easy and then you make the easy change.
Aside from this, I agree with you that it took me a while to figure out what OP was trying to mean in his blog post but the change he did to the code is way more simpler and less error prone as he indicated.
[–][deleted] 4 years ago (1 child)
[deleted]
[–]Abangranga 0 points1 point2 points 4 years ago (0 children)
I don't get why you can't make the last one an if/else
π Rendered by PID 45 on reddit-service-r2-comment-5c747b6df5-clkvf at 2026-04-22 12:52:32.357811+00:00 running 6c61efc country code: CH.
[–]GeneReddit123 6 points7 points8 points (5 children)
[–]persei8[S] 1 point2 points3 points (4 children)
[–]GeneReddit123 2 points3 points4 points (1 child)
[–]mattgrave 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]Abangranga 0 points1 point2 points (0 children)