J
Joey Zhou
My Ruby version is: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]
I find in the installer's help file that String#encode has an option
:fallback.
:fallback Sets the replacement string by the hash for undefined
character. Its key is a such undefined character encoded in source
encoding of current transcoder. Its value can be any encoding until it
can be converted into the destination encoding of the transcoder.
ruby-doc.org has the same explanation:
http://www.ruby-doc.org/core/classes/String.src/M001113.html
However I can't make it effective in my code:
replace_hash = {"\u4ced"=>"x","\u4cd2"=>"y"}
ARGF.each_line do |line|
puts line.encode("gbk", :undef => :replace, :fallback => replace_hash)
end
and I found in this article
(http://www.artima.com/forums/flat.jsp?forum=123&thread=313197), which
said :fallback is new feature in Ruby 1.9.3
I am confused. Can I use :fallback option in latest Ruby 1.9.2p180?
I find in the installer's help file that String#encode has an option
:fallback.
:fallback Sets the replacement string by the hash for undefined
character. Its key is a such undefined character encoded in source
encoding of current transcoder. Its value can be any encoding until it
can be converted into the destination encoding of the transcoder.
ruby-doc.org has the same explanation:
http://www.ruby-doc.org/core/classes/String.src/M001113.html
However I can't make it effective in my code:
replace_hash = {"\u4ced"=>"x","\u4cd2"=>"y"}
ARGF.each_line do |line|
puts line.encode("gbk", :undef => :replace, :fallback => replace_hash)
end
and I found in this article
(http://www.artima.com/forums/flat.jsp?forum=123&thread=313197), which
said :fallback is new feature in Ruby 1.9.3
I am confused. Can I use :fallback option in latest Ruby 1.9.2p180?