sorry for bad English. Why Ruby quoting so strange? Or may be this is a bug?
irb(main):027:0> p eval "\" \+ \\+ \\\+ \\\\+ \\\\\+ \""
produces
=> " + + + \\+ \\+ "
or
irb(main):027:0> puts eval "\" \+ \\+ \\\+ \\\\+ \\\\\+ \""
produces
=> + + + \+ \+
or another example
irb开发者_StackOverflow中文版(main):067:0> " \" " =~ Regexp.new(eval("\" \\\" \""))
=> 0
irb(main):068:0> " + " =~ Regexp.new(eval("\" \\\\+ \""))
=> 0
When you write \" \+ \\+ \\\+ \\\\+ \"
you get " + \+ \+ \\+ "
. After, you use eval
to execute this string, that contains another double-quoted string. You get, then, + + + \+
.
\\
=> \
\x
=> x
(se não for nenhum caso especial, como \n
)
ruby escaping is perfectly good,
eval = evaluate/execute the string
精彩评论