What is your style? ':this_style =>' vs 'this_style:' or depends?

I noticed Michael Hartl’s tutorials seem to use this ‘:this_style =>’ more. What is your take on this?

They both work, it's just a matter of personal style. I find that I get confused easily with the whatever: style, I start to think in terms of CSS and my Ruby brain shuts down.


Agree with Walter its the matter of your preference but I do prefer the new style without the rocket.

I prefer the newer "key: value" style -- partly because I work with JSON frequently, so this way is consistent. Other than that, ask five devs and you'll get seven opinions....


In the Github Ruby Styleguide there’s a note about Hashes:

`Use hashrocket syntax for Hash literals instead of the JSON style

introduced in 1.9.`

I guess the reason is that if you use hashrocket syntax, you can use

any type as a hash key, while with colon the keys are Symbol only.

So, you’ll (pretty much) always have two styles in your app.

Strict styleguides are important. What if we all start to do crazy

things like @VARIABLE or CamelCaseConstant = [1, 2, 3]? (and I’ve

seen such cases, unfortunately).

But in this particular case with hashes, I personally use mixed style.

So, colon for simple key-value hashes, where value is not a Symbol

itself. And hashrocket for mixed DSL hashes with “complex” values.

I have been generally following the GH style guide, but not the hashrocket thing, unless a client mandates it. One thing to note: Github itself as a huge codebase, the main site still runs Rails 2.x, and it makes sense when you have a long term code base, to keep a consistent style across it. I'm not so sure that one needs to be so slavish to that though if you aren't writing code for GH.

Visually I find the hash rocket style really unnerving… I don’t know why! Just like the “<<” which is supposed to be more efficient than “+”. Just pains me to see them but I’m trying to adhere to best practices too.