File.read(filename, :encoding => "Shift_JIS:EUC-JP")

e$B$k$S$-$A$G$9!#e(B

File.read / File.readlinese$B$Ge(B :encoding =>
"enc1:enc2"e$B$H;XDj$G$-$k$He(B
open [email protected]@-$,<h$l$k$H;W$$$^$9!#e(B

Encoding.default_external # => #Encoding:EUC-JP
open(“sjis.txt”, “r:Shift_JIS:EUC-JP”){|f| f.read } # =>
“e$BF|K\8le(B\n”
File.open(“sjis.txt”, “r:Shift_JIS:EUC-JP”){|f| f.read } # =>
“e$BF|K\8le(B\n”
s = File.read(“sjis.txt”, :encoding => “Shift_JIS:EUC-JP”) # =>
“e$BF|K\8le(B\n”
s.encoding # => #Encoding:EUC-JP
s = File.readlines(“sjis.txt”, :encoding => “Shift_JIS:EUC-JP”) # =>
[“e$BF|K\8le(B\n”]

Index: io.c

— io.c (revision 15347)
+++ io.c (working copy)
@@ -5853,7 +5853,7 @@

arg->io = rb_io_open(RSTRING_PTR(argv[0]), “r”);
GetOpenFile(arg->io, fptr);

  • fptr->enc = rb_to_encoding(v);
  •    mode_enc(fptr, StringValueCStr(v));
    
    return;
    }
    }

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs