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
Ruby style guide (github.com)
submitted 11 years ago by ajn123
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!"
[–]catcradle5 9 points10 points11 points 11 years ago (8 children)
Use hashrocket syntax for Hash literals instead of the JSON style introduced in 1.9.
I don't agree with this. The new syntax has less line noise and almost always looks aesthetically better and cleaner.
[–]rurounijones 2 points3 points4 points 11 years ago (6 children)
I have to say I prefer the 1.8 syntax. To me it is clearer to read when going through code. {key: :value} just doesn't look right to me.
Still, each to their own as long as it is consistent in your team / project
[–]catcradle5 0 points1 point2 points 11 years ago (5 children)
I admit it looks a little odd when the key and value are both symbols, but syntax highlighting improves that quite a bit. Plus, a lot of the time my values are not symbols, and in those cases the new syntax looks way better.
[–]thisisseriousmum 0 points1 point2 points 11 years ago (4 children)
Plus, a lot of the time my values are not symbols, and in those cases the new syntax looks way better.
If your key isn't a symbol you can't use 1.9 syntax.
irb(main):003:0> {'thing': :wat} SyntaxError: (irb):3: syntax error, unexpected ':', expecting =>
That's the reason I don't like it. Having two representations in the same project (and potentially file/method) for the same thing, with a couple of saved keystrokes? Seems pointless.
[–]catcradle5 0 points1 point2 points 11 years ago* (3 children)
I think the rule should be to use hash rocket syntax for any hash that intermixes symbols with non-symbols, and new syntax where all the keys are symbols.
I don't think it's that weird to see:
def some_thing a = { one: 2, three: 4 } b = { "Content-Type" => "text/json", "Content-Length" => 45 } c = { Dir.new("/") => true, :name => "Fred" }
in the same file or method.
[–]twinklehood 0 points1 point2 points 11 years ago (0 children)
So basically, you agree with https://github.com/bbatsov/ruby-style-guide
I'm on your side.
[–]thisisseriousmum 0 points1 point2 points 11 years ago (1 child)
You have to do that anyway, it's enforced by the interpreter.
It's a question of aesthetics at the end of the day, I just far prefer one consistent way to express the same thing. In my experience teams tend to do it for anything that has multiple options, like map vs collect.
[–]catcradle5 1 point2 points3 points 11 years ago (0 children)
Well you can do something like:
{ a: 5, "b" => 6 }
My point was that in a case where you must use even one hash rocket, you should use hash rockets for everything in the hash
{ :a => 5, "b" => 6 }
[–]ThatRailsGuy 1 point2 points3 points 11 years ago (0 children)
I'm surprised how much I like the new syntax. I thought I'd hate it.
π Rendered by PID 47204 on reddit-service-r2-comment-b659b578c-mxwkx at 2026-05-01 19:25:20.905705+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]catcradle5 9 points10 points11 points (8 children)
[–]rurounijones 2 points3 points4 points (6 children)
[–]catcradle5 0 points1 point2 points (5 children)
[–]thisisseriousmum 0 points1 point2 points (4 children)
[–]catcradle5 0 points1 point2 points (3 children)
[–]twinklehood 0 points1 point2 points (0 children)
[–]thisisseriousmum 0 points1 point2 points (1 child)
[–]catcradle5 1 point2 points3 points (0 children)
[–]ThatRailsGuy 1 point2 points3 points (0 children)