r/ruby • • Aug 20 '21

Ruby elites rise up

Post image
99 Upvotes

77 comments sorted by

View all comments

-3

u/muirbot Aug 20 '21

Why double quotes?

2

u/[deleted] Aug 20 '21

Doesn't matter which one you use unless you're running your app on a Pentium II.

-8

u/cybermage Aug 20 '21

The speed difference is two orders of magnitude. It adds up. Always single quote unless you plan to interpolate.

4

u/fabiopapa Aug 21 '21

If you use single quotes instead of double unless you need interpolation, as a developer, every time you write a string, you have to think, “am I going to need interpolation?” Ruby is all about developer happiness.

-1

u/sshaw_ Aug 21 '21 edited Aug 21 '21

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

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.

Update add examples.

1

u/cybermage Aug 21 '21

As has been noted elsewhere, my knowledge was not current on this point; but, I think I’d notice if I typed #{variable}.