ruby-1.9.2-p180 :023 > buffer = ''
ruby-1.9.2-p180 :024 > i = "buffer << \\\"[@user_id,@account_id]\\\""
=> "buffer << \\\"[@user_id,@account_id]\\\""
ruby-1.9.2-p180 :025 > eval i
SyntaxError: (eval):1: syntax error, unexpected $undefined
buffer << \"[@user_id,@account_id]\"
^
(eval):1: unterminated string me开发者_如何转开发ets end of file
from (irb):25:in `eval'
ruby-1.9.2-p180 :026 > j = "buffer << \"[@user_id,@account_id]\""
=> "buffer << \"[@user_id,@account_id]\""
ruby-1.9.2-p180 :027 > eval j
=> "[@user_id,@account_id]"
How do I convert i into j?
or
How to convert "buffer << \\"[@user_id,@account_id]\\"" into "buffer << \"[@user_id,@account_id]\" ?
The answer to your question "how do i convert i into j":
i.gsub(/\\/, '')
However, it very much looks as if the question is wrong and should rather be "how to I rewrite the surrounding code in order not having to do stuff like this in the first place".
精彩评论