天天看點

Ruby中關于單引号和雙引号的轉義

單引号和%q隻轉義\(反斜杠)和‘(單引号),其他不轉義

雙引号和%Q轉義所有。

a1 = 'hello \\world'
a2 = 'hello \nworld'
a3 = 'that\'s nice!'
b1 = "hello \\world"
b2 = "hello \nworld"
b3 = "that\'s nice!"
puts a1
puts a2
puts a3
puts b1
puts b2
puts b3
           

=>

hello \world

hello \nworld

that's nice!

hello \world

hello 

world

that's nice!