我正在尝试使用 undecoder gem,它给我一些字符串带来了问题:
require 'unidecoder'
str = "\u00A3"
str.to_ascii
#: (C:/Ruby193/lib/ruby/gems/1.9.1/gems/unidecoder-1.1.1/lib/unidecoder/data/x00.yml): 在第 2 行解析引号 d 标量时发现未知转义字符第 3 列来自 C:/Ruby193/lib/ruby/1.9.1/psych.rb:203:in
parse' from C:/Ruby193/lib/ruby/1.9.1/psych.rb:203:in
parse_stream' 来自 C:/Ruby193/lib/ruby/1.9.1/psych.rb:151:inparse' from C:/Ruby193/lib/ruby/1.9.1/psych.rb:127:in
load' 来自 C :/Ruby193/lib/ruby/1.9.1/psych.rb:297:inblock in load_file' from C:/Ruby193/lib/ruby/1.9.1/psych.rb:297:in
open' 来自 C:/Ruby193/lib/ruby/1.9.1/psych.rb:297:inload_file' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/unidecoder-1.1.1/lib/unidecoder.rb:8:in
block in '来自 C:/Ruby193 /lib/ruby/gems/1.9.1/gems/unidecoder-1.1.1/lib/unidecoder.rb:78:inyield' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/unidecoder-1.1.1/lib/unidecoder.rb:78:in
default' 来自 C:/Ruby193/lib/ruby/gems/1.9.1/gems/unidecoder- 1.1.1/lib/unidecoder.rb:78:indecode_char' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/unidecoder-1.1.1/lib/unidecoder.rb:39:in
block in decode' 来自 C:/Ruby193/lib/ruby/gems/1.9.1/gems/unidecoder-1.1.1/lib/unidecoder.rb:37:ingsub' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/unidecoder-1.1.1/lib/unidecoder.rb:37:in
从 C:/Ruby193/lib/ruby/gems/1.9.1/gems/unidecoder-1.1.1/lib/unidecoder.rb:16:in 解码to_ascii' from (irb):21 from C:/Ruby193/bin/irb:12:in
'>>
更糟糕的是,我无法通过以下方式捕获错误:
foo = str.to_ascii rescue 'x'
有谁知道这里发生了什么?