Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #3428

Does String#encode in Ruby 1.9.2 have option :fallback?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!talisker.lacave.net!lacave.net!not-for-mail
From Joey Zhou <yimutang@gmail.com>
Newsgroups comp.lang.ruby
Subject Does String#encode in Ruby 1.9.2 have option :fallback?
Date Sun, 24 Apr 2011 05:49:44 -0500
Organization Service de news de lacave.net
Lines 28
Message-ID <815cbeada89786414de358800a28765e@ruby-forum.com> (permalink)
NNTP-Posting-Host bristol.highgroove.com
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Trace talisker.lacave.net 1303642622 89191 65.111.164.187 (24 Apr 2011 10:57:02 GMT)
X-Complaints-To abuse@lacave.net
NNTP-Posting-Date Sun, 24 Apr 2011 10:57:02 +0000 (UTC)
X-Received-From This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway
X-Mail-Count 382115
X-Ml-Name ruby-talk
X-Rubymirror Yes
X-Ruby-Talk <815cbeada89786414de358800a28765e@ruby-forum.com>
Xref x330-a1.tempe.blueboxinc.net comp.lang.ruby:3428

Show key headers only | View raw


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?

-- 
Posted via http://www.ruby-forum.com/.

Back to comp.lang.ruby | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Does String#encode in Ruby 1.9.2 have option :fallback? Joey Zhou <yimutang@gmail.com> - 2011-04-24 05:49 -0500
  Re: Does String#encode in Ruby 1.9.2 have option :fallback? "Y. NOBUOKA" <nobuoka@r-definition.com> - 2011-04-24 06:30 -0500
    Re: Does String#encode in Ruby 1.9.2 have option :fallback? Joey Zhou <yimutang@gmail.com> - 2011-04-24 07:45 -0500
      Re: Does String#encode in Ruby 1.9.2 have option :fallback? "Y. NOBUOKA" <nobuoka@r-definition.com> - 2011-04-24 08:28 -0500
        Re: Does String#encode in Ruby 1.9.2 have option :fallback? Joey Zhou <yimutang@gmail.com> - 2011-04-24 09:40 -0500

csiph-web