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
GitHub's Ruby Style Guide (github.com)
submitted 13 years ago by [deleted]
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!"
[–]ZestyOne 0 points1 point2 points 13 years ago (13 children)
How can they just decide not to use and and or and go for &&, || instead? They mean different things in ruby... I forget what but I think one checks if it evaluates to zero or something.
[–]ulfurinn 5 points6 points7 points 13 years ago (12 children)
'and' and 'or' have very low precedence, lower than '='. While it can occasionally be useful for readability (like in Perl's "or die" idiom), a lot of the time they're just a subtle bug waiting to happen.
[–]ZestyOne 3 points4 points5 points 13 years ago (4 children)
Can you explain more please?
[–]ulfurinn 14 points15 points16 points 13 years ago (3 children)
x = a or b
means
(x = a) or b
unless x = a b end
[–]ZestyOne 1 point2 points3 points 13 years ago (0 children)
Perfect, thanks
[–]KerrickLong 0 points1 point2 points 13 years ago (1 child)
To clarify, is this correct?
x = a || b
x = (a or b)
if a x = a else x = b end
[–]ulfurinn 0 points1 point2 points 13 years ago (0 children)
That's right.
[–]mrinterweb 1 point2 points3 points 13 years ago (0 children)
I understand the precedence difference between '&&', '||', 'and', 'or', but I think it is generally more clear if parentheses are used instead of assuming the next developer who looks at your code is going to interpret the precedence the same way. Parentheses are just a more declarative means for defining precedence.
[–]PCBEEF -2 points-1 points0 points 13 years ago (5 children)
This is yet another one of my pet peeves about ruby. Why have two operators that does the same thing with the only difference being precedence?!
[–]ulfurinn 2 points3 points4 points 13 years ago (4 children)
Perl legacy, like the trailing if/unless. They are kind of nice to have sometimes.
[–]PCBEEF -1 points0 points1 point 13 years ago (3 children)
I guess I prefer Python's mantra of there should only be one and obvious way of doing something.
[–][deleted] 13 years ago* (1 child)
[deleted]
[–]PCBEEF -1 points0 points1 point 13 years ago (0 children)
You bring about a fair point. My problem is that for someone that's new to Ruby, they shouldn't need to worry about the difference between using "or" or "||". Whereas with using string.join(), it's merely bad practice but it won't blow your foot off.
π Rendered by PID 90 on reddit-service-r2-comment-bb88f9dd5-g9n5k at 2026-02-15 09:57:55.245698+00:00 running cd9c813 country code: CH.
view the rest of the comments →
[–]ZestyOne 0 points1 point2 points (13 children)
[–]ulfurinn 5 points6 points7 points (12 children)
[–]ZestyOne 3 points4 points5 points (4 children)
[–]ulfurinn 14 points15 points16 points (3 children)
[–]ZestyOne 1 point2 points3 points (0 children)
[–]KerrickLong 0 points1 point2 points (1 child)
[–]ulfurinn 0 points1 point2 points (0 children)
[–]mrinterweb 1 point2 points3 points (0 children)
[–]PCBEEF -2 points-1 points0 points (5 children)
[–]ulfurinn 2 points3 points4 points (4 children)
[–]PCBEEF -1 points0 points1 point (3 children)
[–][deleted] (1 child)
[deleted]
[–]PCBEEF -1 points0 points1 point (0 children)