I want to tell ruby that everything is utf8, except when stated otherwise, so I dont have to place these # encoding: utf-8
comments everywhere.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can either:
- set your RUBYOPT environment variable to "-E utf-8"
- or use https://github.com/m-ryan/magic_encoding
回答2:
If you're using environment variables, the general way is to use LC_ALL / LANG
Neither is set : fallback to US-ASCII
$ LC_ALL= LANG= ruby -e 'p Encoding.default_external'
#<Encoding:US-ASCII>
Either is set : that value is used
$ LC_ALL=en_US.UTF-8 LANG= ruby -e 'p Encoding.default_external'
#<Encoding:UTF-8>
$ LC_ALL= LANG=en_US.UTF-8 ruby -e 'p Encoding.default_external'
#<Encoding:UTF-8>
Both are set : LC_ALL takes precedence
$ LC_ALL=C LANG=en_US.UTF-8 ruby -e 'p Encoding.default_external'
#<Encoding:US-ASCII>
$ LC_ALL=en_US.UTF-8 LANG=C ruby -e 'p Encoding.default_external'
#<Encoding:UTF-8>
回答3:
I just upgraded from 1.9 to 2.0, but for some reason the default external encoding was still set to ASCII. I was able to fix it by typing the following in Terminal:
export RUBYOPT='-E utf-8'