- 浏览: 4031 次
- 性别:
- 来自: 杭州
最近访客 更多访客>>
最新评论
-
huling:
在rails中么?我也遇到同样的问题,查看了原代码,发现在
C ...
rails中builder如何正确输出中文, -
defier:
呵呵。没有用啦。
rails中builder如何正确输出中文, -
cfc:
$KCODE = 'GB2312'require 'jcode ...
rails中builder如何正确输出中文,
评论
C:\ruby\lib\ruby\gems\1.8\gems\activesupport-2.0.2\lib\active_support\multibyte\chars.rb
中有说明,缺省的multibyte字符串handler是按utf8来处理的。应该需要自己hack代码。
# Chars enables you to work transparently with multibyte encodings in the Ruby String class without having extensive
# knowledge about the encoding. A Chars object accepts a string upon initialization and proxies String methods in an
# encoding safe manner. All the normal String methods are also implemented on the proxy.
#
# String methods are proxied through the Chars object, and can be accessed through the +chars+ method. Methods
# which would normally return a String object now return a Chars object so methods can be chained.
#
# "The Perfect String ".chars.downcase.strip.normalize #=> "the perfect string"
#
# Chars objects are perfectly interchangeable with String objects as long as no explicit class checks are made.
# If certain methods do explicitly check the class, call +to_s+ before you pass chars objects to them.
#
# bad.explicit_checking_method "T".chars.downcase.to_s
#
# The actual operations on the string are delegated to handlers. Theoretically handlers can be implemented for
# any encoding, but the default handler handles UTF-8. This handler is set during initialization, if you want to
# use you own handler, you can set it on the Chars class. Look at the UTF8Handler source for an example how to
# implement your own handler. If you your own handler to work on anything but UTF-8 you probably also
# want to override Chars#handler.
#
# ActiveSupport::Multibyte::Chars.handler = MyHandler
#
# Note that a few methods are defined on Chars instead of the handler because they are defined on Object or Kernel
# and method_missing can't catch them.
require 'jcode'
試試看?