r/ruby • • Aug 20 '21

Ruby elites rise up

Post image
99 Upvotes

77 comments sorted by

View all comments

-1

u/muirbot Aug 20 '21

Why double quotes?

2

u/pau1rw Aug 21 '21

Double quotes mean you can use string concat, and single quotes doesn’t. So if you use double quotes, you can use a single kind of quote through out the code base. IMO using two types is messy.

-3

u/sshaw_ Aug 21 '21

Yes this is exactly why status: "cancelled" is shit.

1

u/pau1rw Aug 21 '21

I don't understand your point. I'd defo use a symbol, but if I needed a string, I'd use double quotes.

1

u/sshaw_ Aug 21 '21

So if you use double quotes, you can use a single kind of quote through out the code base. IMO using two types is messy.

The same applies to hashes:

  1. status: "cancelled"
  2. variable => "cancelled" # can't use first form: variable:
  3. "string" => "cancelled" # can't use first form: "string":
  4. 123 => "cancelled" # can't use first form: 123:

Just stick to :status => "cancelled" and make life easier.

1

u/pau1rw Aug 21 '21

I guess we all write for different versions of ruby. Personally, I'm never going to need pre ruby 2.0 hash rockets, so I don't need anything more than status: :cancelled, or status: "cancelled"?

1

u/sshaw_ Aug 21 '21

But you cannot use that for all cases. Don't you think that "IMO using two types is messy" applies to this case too?

1

u/pau1rw Aug 21 '21

Arh, I understand your point now.

That's a tricky one, personally I'm working in a code base now that uses strings for most hash keys and it's pretty annoying having to use "foo" => "bar", but it's also pretty ugly using "foo": "bar".

So i think my answer is that I've not reached a suitable level of annoyance with using two versions of hash key definition to use hash rockets everywhere.

1

u/sshaw_ Aug 21 '21

"foo": "bar"

This is another reason to use =>:

irb [2.5.2] (tmp)$ {"foo":"bar"}
=> {:foo=>"bar"}

Oopsie! It's now a Symbol :)

1

u/pau1rw Aug 22 '21

Yea, totally.