5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Encoding::default_externalとEncoding::default_internalをデフォルトでUTF-8にしておく

Posted at

まとめ

環境変数RUBYOPT=-Eutf-8:utf-8しましょう。

ついでにLANG=ja_JP.UTF-8しましょう。

なぜ(私にとって)必要か

おそらくLinuxでLANG=ja_JP.UTF-8してあれば上記設定はいらないと思います。
私はWindowsでもShift_JISを使わないことに決めたので、単純に全面的にUTF-8で入出力してほしいです。
Windowsだと出力はShift_JIS(Windows-31J)、入力はnil(ASCII-8BIT)になっていて、時々force_encodingしたりencodeしたりが必要なので、めんどくさくなったので設定しました。
Net::SSHでLinuxホストから多バイトを受け取る場合なども問題が少なくなると思います。

問題点

cmd.exeで実行すると文字化けしそうです。ターミナルエミュレータを入れていれば多分問題無いと思います。

コンソールでgetsで入力待ちになるようなコマンドで日本語入力すると問題が出そうです。ターミナルエミュレータで入力も変換してくれていれば大丈夫だと思いますが、特に検証していません。

そういうものがあるか知りませんが、Encoding基準でなくシステム名でデフォルト文字コードを判定している場合は問題になるかも。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?