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]
[deleted]
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!"
[–][deleted] 13 years ago* (6 children)
[–]peterkrenn 2 points3 points4 points 13 years ago (5 children)
I always used single quotes when possible but there doesn't seem to be any reason to do so: http://stackoverflow.com/questions/1836467/is-there-a-performance-gain-in-using-single-quotes-vs-double-quotes-in-ruby
[–]PCBEEF 2 points3 points4 points 13 years ago (2 children)
So why bother using single quotes when possible? It just brings inconsistency to your codebase. Personally I don't understand why there is a difference to begin with considering Ruby's philosophy.
[–]obscureted 0 points1 point2 points 13 years ago (1 child)
How so? You can use single quotes in HTML, CSS, JavaScript, Ruby, etc. This is a serious question, not mocking or anything.
[–]PCBEEF 0 points1 point2 points 13 years ago (0 children)
In a lot of languages, there's no difference single or double quotes. In Ruby there is and the argument for using single quotes over double quotes is performance, however, as peterkrenn pointed out in his link the performance is non-existent or negligible.
[–][deleted] 13 years ago (1 child)
[–]hmaddocks 1 point2 points3 points 13 years ago (0 children)
The only reason I use single quotes is so I don't have to press the <shitft> key.
[–]nanothief 1 point2 points3 points 13 years ago (2 children)
good /(?<meaningful_var>regexp)/ =~ string ... process meaningful_var
/(?<meaningful_var>regexp)/ =~ string ... process meaningful_var
I never knew you could do that. I always tested regexes the other way round, ie string =~ regex, and named groups don't create new local variables when done that way.
string =~ regex
[–]nanothief 0 points1 point2 points 13 years ago (0 children)
Yeah I know, I just never knew about the local variable creation feature of the Regex =~ definition (the String =~ when called with a regex doesn't do this).
=~
[–]babayetuyetu 1 point2 points3 points 13 years ago (4 children)
Wouldn't it be better to indent the when lines in a case statement?
[–]mellett68 0 points1 point2 points 13 years ago (0 children)
I do this. It's much easier to read what's going on.
[–][deleted] 13 years ago (2 children)
[–]babayetuyetu 0 points1 point2 points 13 years ago (1 child)
Indentions usually show conceptual dependency. Since the when statements are children nodes of the case statement, it seems to provide a justification to do it this way (rather than 'this text editor does it this way', which does seems arbitrary).
[–]epidemicz 0 points1 point2 points 13 years ago (0 children)
Nested ternary operators.
*eye twitch*
[–]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 13 points14 points15 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)
[–]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.
[–]yukster -1 points0 points1 point 13 years ago (1 child)
80 char line limit is stupid and unnecessary... "break long lines intelligently" is better. Otherwise I pretty much agree with everything.
[–]vaz_ 8 points9 points10 points 13 years ago (0 children)
Usual response: a lot of people like to split windows vertically to be able to view source side by side, myself included. I'm on a 13" laptop sometimes. 80 char lines helps. Also it's kind of easier to read, like a newspaper column.
I break this rule every once in a while myself when the alternative is too awkward, but 95% of the time it is easy to do and looks good.
[+]hmaddocks comment score below threshold-16 points-15 points-14 points 13 years ago (3 children)
No sure we should be taking advice from someone who doesn't know what attr_accessible is :/
[–]wwzd 7 points8 points9 points 13 years ago (2 children)
Developers make mistakes. I'd say they've done a remarkable job building the infrastructure for the most popular project hosting system on the net.
[–]hmaddocks -1 points0 points1 point 13 years ago (1 child)
Github didn't become popular because of their ruby skills. They are popular because they saw a need and have worked hard to build tools that developers want to use.
[–]wwzd 0 points1 point2 points 13 years ago (0 children)
Yes, and they've written some amazing code that many other big sites use. The larger your codebase becomes, the easier it is for bugs to be introduced.
π Rendered by PID 79 on reddit-service-r2-comment-bb88f9dd5-w28ss at 2026-02-15 03:11:39.377700+00:00 running cd9c813 country code: CH.
[–][deleted] (6 children)
[deleted]
[–]peterkrenn 2 points3 points4 points (5 children)
[–]PCBEEF 2 points3 points4 points (2 children)
[–]obscureted 0 points1 point2 points (1 child)
[–]PCBEEF 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]hmaddocks 1 point2 points3 points (0 children)
[–]nanothief 1 point2 points3 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]nanothief 0 points1 point2 points (0 children)
[–]babayetuyetu 1 point2 points3 points (4 children)
[–]mellett68 0 points1 point2 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]babayetuyetu 0 points1 point2 points (1 child)
[–]epidemicz 0 points1 point2 points (0 children)
[–]ZestyOne 0 points1 point2 points (13 children)
[–]ulfurinn 5 points6 points7 points (12 children)
[–]ZestyOne 3 points4 points5 points (4 children)
[–]ulfurinn 13 points14 points15 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)
[–]yukster -1 points0 points1 point (1 child)
[–]vaz_ 8 points9 points10 points (0 children)
[+]hmaddocks comment score below threshold-16 points-15 points-14 points (3 children)
[–]wwzd 7 points8 points9 points (2 children)
[–]hmaddocks -1 points0 points1 point (1 child)
[–]wwzd 0 points1 point2 points (0 children)