你喜欢哪种风格的 Ruby 字符串引用? [英] Which style of Ruby string quoting do you favour?
问题描述
您喜欢哪种风格的 Ruby 字符串引用?直到现在我一直使用 'singlequote'
除非字符串包含某些转义序列或插值,在这种情况下我显然必须使用 双引号"
.
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 interpolation, in which case I obviously have to use "double quotes"
.
然而,真的有什么理由不到处使用双引号吗?
However, is there really any reason not to just use double quoted strings everywhere?
推荐答案
如果必须对双引号进行转义,请不要使用双引号.并且不要陷入单引号与双引号"的陷阱.Ruby 对字符串文字的任意分隔符有很好的支持:
Don't use double quotes if you have to escape them. And don't fall in "single vs double quotes" trap. Ruby has excellent support for arbitrary delimiters for string literals:
网站镜像 - https://web.archive.org/web/20160310224440/http://rors.org/2008/10/26/dont-escape-in-strings
原始站点 -http://rors.org/2008/10/26/dont-转义字符串
这篇关于你喜欢哪种风格的 Ruby 字符串引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!