开发者

How can I input multibyte characters in rails console (or irb)?

开发者 https://www.devze.com 2023-02-02 13:17 出处:网络
guys. I am developing a Chinese application with rails. Now I want to input some Chinese characters in rails console but 开发者_StackOverflow社区cannot do that, either in irb.

guys. I am developing a Chinese application with rails. Now I want to input some Chinese characters in rails console but 开发者_StackOverflow社区cannot do that, either in irb.

Any guys who have the experience to solve this problem? I would appreciate your help!


Based on @Jimmy-Huang's answer, these are the steps I followed on Mac Leopard using rvm and ruby 1.9.2:

rvm package install readline
rvm remove 1.9.2
rvm install 1.9.2 --with-readline-dir=$rvm_path/usr

That resulted in some errors, particularly when trying bundle install:

uninitialized constant Gem::SilentUI

It turned out that's due to an older version of bundler and this gets rid of it:

gem install bundler


I found the solution for me, it need to re-compile the readline. And now I can input non-ASCII characters!

Because I am using rvm, so I found this article to teach you how to re-compile readline under rvm. http://rvm.beginrescueend.com/packages/readline/

And for someone who is not using rvm, maybe you can follow this post and have a try: http://henrik.nyh.se/2008/03/irb-readline

By the way, ruby-1.9.2 irb already supports non-ASCII inputing.


Check out the pack method on array: http://ruby-doc.org/core-1.8.7/classes/Array.html#M000287

I think you'd want:

[111 ,222, 333].pack(U*)

Here is an interesting discussion on the subject had with Matz:

http://www.ruby-forum.com/topic/134919

0

精彩评论

暂无评论...
验证码 换一张
取 消