如何在rails控制台(或irb)中输入多字节字符?
伙计们。我正在用rails开发一个中文应用程序。现在我想在rails控制台中输入一些汉字,但在irb中都无法做到这一点。
有哪位大佬有解决这个问题的经验吗?我将感谢您的帮助!
guys. I am developing a Chinese application with rails. Now I want to input some Chinese characters in rails console but cannot do that, either in irb.
Any guys who have the experience to solve this problem? I would appreciate your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 @Jimmy-Huang 的回答,以下是我使用 rvm 和 ruby 1.9.2 在 Mac Leopard 上遵循的步骤:
这导致了一些错误,特别是在尝试
捆绑安装
时:事实证明,这是由于旧版本的捆绑程序造成的,这将消除它:
Based on @Jimmy-Huang's answer, these are the steps I followed on Mac Leopard using rvm and ruby 1.9.2:
That resulted in some errors, particularly when trying
bundle install
:It turned out that's due to an older version of bundler and this gets rid of it:
我找到了适合我的解决方案,它需要重新编译readline。现在我可以输入非 ASCII 字符了!
因为我使用的是rvm,所以找到这篇文章教大家如何在rvm下重新编译readline。 http://rvm.beginrescueend.com/packages/readline/
对于那些不是使用rvm,也许你可以按照这篇文章尝试一下:
http://henrik.nyh.se/2008/03/irb-readline
顺便说一下,ruby-1.9.2 irb 已经支持非 ASCII 输入。
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.
检查数组上的 pack 方法:
http://ruby-doc.org/core-1.8.7 /classes/Array.html#M000287
我想你会想要:
这是与 Matz 就该主题进行的有趣讨论:
http://www.ruby-forum.com/topic/134919
Check out the pack method on array:
http://ruby-doc.org/core-1.8.7/classes/Array.html#M000287
I think you'd want:
Here is an interesting discussion on the subject had with Matz:
http://www.ruby-forum.com/topic/134919