The best Ruby Chinese encoding Ruby Chinese encoding Tutorial In 2024, In this tutorial you can learn Examples,
Previous chapters we have learned how to use Ruby output "Hello, World!", English no problem, but if you output Chinese characters "Hello, World" is likely to encounter Chinese coding problem.
Ruby files if the encoding is not specified in the implementation process will be given:
#!/usr/bin/ruby -w puts "你好,世界!";
The above program execution output is:
invalid multibyte char (US-ASCII)
The above error message shows the Ruby use with ASCII encoding to read the source, the Chinese will be garbled, the solution is just the beginning of the file on# - * - coding: UTF- 8 - * - (EMAC written) or # coding = utf-8on the line.
The output is:
你好,世界!
So if we re-learning process, the source code file, then with the Chinese encoding, you need to pay attention to two things: