[#23231] What do you think about changing the return value of Kernel#require and Kernel#load to the source encoding of the required file? — =?ISO-8859-15?Q?Wolfgang_N=E1dasi-Donner?= <ed.odanow@...>

Dear Ruby developers and users!

8 messages 2009/04/17

[#23318] [Feature #1408] 0.1.to_r not equal to (1/10) — Heesob Park <redmine@...>

Feature #1408: 0.1.to_r not equal to (1/10)

19 messages 2009/04/26

[ruby-core:23234] Re: What do you think about changing the return value of Kernel#require and Kernel#load to the source encoding of the required file?

From: Wolfgang Nádasi-Donner <ed.odanow@...>
Date: 2009-04-17 14:07:08 UTC
List: ruby-core #23234
Michael Neumann schrieb:
> Can you describe more precise what exactly is your problem. Wouldn't it be 
> more wise to convert the Ruby libraries to UTF-8, to avoid conversion 
> problems?
If I have control over the libraries, usually no problem exists, but if 
I use several other libraries, including those coming from *nix systems, 
  the named encodings can appear.

If there ist for example a source starting with...

# coding: Windows-1252
require 'somelib.rb' # ...which includes class 'Otto'
x = Otto.new("竄ャ")
#...rest of code

...it will give problems if the encodings of 'somelib.rb' is
utf-8 (e.g.).

In the moment the return code of Kernel#load is always true (if the 
source exists) and the return code of Kernel#require ist true, if the 
source was loaded. If these methods return an encoding instead of true,
there should be no problems with existing code, because the returned 
encodig acts like true (every value not false or nil will be interpreted 
as true in logical expressions).

If I can change the example code to...

# coding: Windows-1252
unless (require 'somelib.rb') == __ENCODING__
   warn 'possible encoding mismatch: somelib.rb'
end
x = Otto.new("竄ャ")
#...rest of code

..., It is as least helpful for debugging. In more sophisticated 
applications the code can be adapted to special needs.

Wolfgang Nテ。dasi-Donner

In This Thread