Which style of Ruby string quoting do you favour?

后端 未结 9 1809
挽巷
挽巷 2020-11-30 00:31

Which style of Ruby string quoting do you favour? Up until now I\'ve always used \'single quotes\' unless the string contains certain escape sequences or interp

9条回答
  •  无人及你
    2020-11-30 01:05

    I see arguments for both:

    For using mostly double quotes:

    • The github ruby style guideline advocates always using double quotes:

    enter image description here

    • It's easier to search for a string foobar by searching for "foobar" if you were consistent with quoting. However, I'm not. So I search for ['"]foobar['"] turning on regexps.

    For using some combination of single double quotes:

    • Know if you need to look for string interpolation.
    • Might be slightly faster (although so slight it wasn't enough to affect the github style guide).

提交回复
热议问题