I'm reading about ruby programming best practices and I found this page: https://github.com/styleguide/ruby
Inside this, a "Hashes" section explain that:
# bad
user = {
login: "defunkt",
name: "Chris Wanstrath"
}
# bad
user = {
login: "defunkt",
name: "Chris Wanstrath",
"followers-count" => 52390235
}
# good
user = {
:login => "defunkt",
:name => "Chris Wanstrath",
"followers-count" => 52390235
}
Why the first block are marked as bad if I can read better than the last block?
It's just a style guide GitHub uses for its code base, nothing more. They probably prefer it because a lot of their code had been written before Ruby 1.9 was established and they want to keep things consistent.
I personally use the new syntax everywhere I can. Note that the last example is bad on its own because it mixes symbol and string keys together.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With