Issue #6679 has been updated by naruse (Yui NARUSE).


ko1 (Koichi Sasada) wrote:
> (2012/07/23 22:57), Perry Smith wrote:
>  > Making it a configuration option may be nice anyway.
>  
>  +1

diff --git a/ruby.c b/ruby.c
index ab4b674..d6a8a91 100644
--- a/ruby.c
+++ b/ruby.c
@@ -702,6 +702,7 @@ static long
 proc_options(long argc, char **argv, struct cmdline_options *opt, int envopt)
 {
     long n, argc0 = argc;
+    int opt_K_p = FALSE;
     const char *s;
 
     if (argc == 0)
@@ -909,6 +910,7 @@ proc_options(long argc, char **argv, struct cmdline_options *opt, int envopt)
 		    break;
 		}
 		if (enc_name) {
+		    opt_K_p = TRUE;
 		    opt->src.enc.name = rb_str_new2(enc_name);
 		    if (!opt->ext.enc.name)
 			opt->ext.enc.name = opt->src.enc.name;
@@ -1013,10 +1015,8 @@ proc_options(long argc, char **argv, struct cmdline_options *opt, int envopt)
 		    if (!*(s = ++p)) break;
 		    set_encoding_part(internal);
 		    if (!*(s = ++p)) break;
-#if defined ALLOW_DEFAULT_SOURCE_ENCODING && ALLOW_DEFAULT_SOURCE_ENCODING
 		    set_encoding_part(source);
 		    if (!*(s = ++p)) break;
-#endif
 		    rb_raise(rb_eRuntimeError, "extra argument for %s: %s",
 			     (arg[1] == '-' ? "--encoding" : "-E"), s);
 #	undef set_encoding_part
@@ -1028,11 +1028,9 @@ proc_options(long argc, char **argv, struct cmdline_options *opt, int envopt)
 	    else if (is_option_with_arg("external-encoding", Qfalse, Qtrue)) {
 		set_external_encoding_once(opt, s, 0);
 	    }
-#if defined ALLOW_DEFAULT_SOURCE_ENCODING && ALLOW_DEFAULT_SOURCE_ENCODING
 	    else if (is_option_with_arg("source-encoding", Qfalse, Qtrue)) {
 		set_source_encoding_once(opt, s, 0);
 	    }
-#endif
 	    else if (strcmp("version", s) == 0) {
 		if (envopt) goto noenvopt_long;
 		opt->dump |= DUMP_BIT(version);
@@ -1097,6 +1095,9 @@ proc_options(long argc, char **argv, struct cmdline_options *opt, int envopt)
     }
 
   switch_end:
+    if (opt_K_p)
+	rb_warning("-K is specified; it is for 1.8 compatibility and may cause odd behavior");
+
     return argc0 - argc;
 }
 
@@ -1268,9 +1269,6 @@ process_options(int argc, char **argv, struct cmdline_options *opt)
 	    opt->intern.enc.name = int_enc_name;
     }
 
-    if (opt->src.enc.name)
-	rb_warning("-K is specified; it is for 1.8 compatibility and may cause odd behavior");
-
     if (opt->dump & DUMP_BIT(version)) {
 	ruby_show_version();
 	return Qtrue;
----------------------------------------
Feature #6679:  Default Ruby source file encoding to utf-8
https://bugs.ruby-lang.org/issues/6679#change-28379

Author: claytrump (Clay Trump)
Status: Assigned
Priority: Normal
Assignee: naruse (Yui NARUSE)
Category: 
Target version: 


Let's change the default encoding for Ruby source files from US-ASCII
to UTF-8 in Ruby 2.0

??? Convention over Configuration
??? Ruby 1.9 forced encoding for code that was not pure ASCII, so
existing codebase already has magic comments.


In Ruby 2.0, "# encoding: utf-8" can be the default.
--
<lay trum/>


-- 
http://bugs.ruby-lang.org/