4
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.

Ruby1.8xから2.2xに変えたら案の定動かないの巻き Windows7

Last updated at Posted at 2016-01-27

#:ghost: Stringにto_aしたらダメ

ary = ""
#ary.to_a #ダメ
ary = ary.kind_of?(String) ? ary.split("\n") : ary

#:ghost: 文字コード関連で色々怒られる

ArgumentError: invalid byte sequence in Windows-31J

こんなエラーが各所で出る。
これはWinのせいか?EUCだったのをUTF-8にしちゃったからか?
UTF-8ですよーってRubyに教えてあげれば解決です

\#!/usr/bin/ruby
Encoding.default_external = "utf-8"

しかしこれだと1.8で動かなくなってしまう切り替えていくのだからいいといえばいいのだけど一応1.8でも動くようにしておいてあげようと下記の方法

\#!/usr/bin/ruby -Ku
#Encoding.default_external = "utf-8"

と-Kuを付けてUTF-8指定する

-Ks Sjis
-Ke EUC
-Ku UTF-8

これくらいで今のとこ動いてます。

4
5
2

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
4
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?