Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails, convert projectwide single quotes to double quotes

I wonder if anyone has come up with a shortcut to correctly convert ALL single quotes to double quotes in a new rails project. Thank you in advance. I would do that at the end of generating new project with a template.rb

like image 955
webgen Avatar asked Mar 25 '19 10:03

webgen


People also ask

How do you replace single quotes with double quotes?

Use the String. replace() method to replace double with single quotes, e.g. const replaced = str. replace(/"/g, "'"); . The replace method will return a new string where all occurrences of double quotes are replaced with single quotes.

How do you add a double quote to a string in Ruby?

Single-quoted and double-quoted strings are (almost) equivalent in Ruby. Of course, you have to escape \' inside single-quoted strings and \" inside double-quoted strings.

Are single and double quotes interchangeable?

The short answer is that it depends on the country that you are writing in. In British and Australian English, one typically uses single quotes. If you're writing in North America, double quote marks are typically used.

Can char use double quotes?

Use the CHAR functionYou can also insert a double quote in an Excel formula using the CHAR function.


1 Answers

I would also use rubocop for that:

rubocop --safe-auto-correct --only "Style/StringLiterals" .

As spickermann suggested

like image 79
Martin Zinovsky Avatar answered Oct 19 '22 07:10

Martin Zinovsky