什么时候在Rails应用中使用单引号和双引号[duplicate]

时间:2022-10-28 15:38:43

Possible Duplicate:
Which style of Ruby string quoting do you favour?

可能重复:你喜欢哪种风格的Ruby字符串引用?

Is there a good rule of thumb about when to use single or double quotes in ruby, and especially rails apps?

在ruby中,特别是在rails应用中,什么时候使用单引号或双引号是一个很好的经验法则吗?

Doesn't one use more memory than the other? Is there any sort of convention the rails community has settled on?

一个人不是比另一个人使用更多的内存吗?rails社区有什么约定吗?

1 个解决方案

#1


50  

The difference between using double quotes versus single quotes is that double quotes interpret escaped characters and single quotes preserve them.

使用双引号和单引号的区别在于双引号解释转义字符和单引号保留它们。

Here is an example

这是一个例子

 puts "i \n love \n ruby"
 #i 
 #love 
 #ruby

and

 puts 'i \n love \n ruby'
 #i \n love \n ruby

#1


50  

The difference between using double quotes versus single quotes is that double quotes interpret escaped characters and single quotes preserve them.

使用双引号和单引号的区别在于双引号解释转义字符和单引号保留它们。

Here is an example

这是一个例子

 puts "i \n love \n ruby"
 #i 
 #love 
 #ruby

and

 puts 'i \n love \n ruby'
 #i \n love \n ruby