[#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:23233] 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: Michael Neumann <mneumann@...>
Date: 2009-04-17 13:29:15 UTC
List: ruby-core #23233
Wolfgang N叩dasi-Donner wrote:

> Dear Ruby developers and users!
> 
> Starting with Ruby 1.9 it can often happen, that the encoding of the
> program source differs from the encoding of required files. This can
> lead to some problems if String constants are passed as parameters or if
>   String constants will be returned.
> 
> If Kernel#load and Kernel#require returns the source encoding (the value
> of __ENCODING__) of the required file instead of "true", possible
> problems based on incompatible source encodings can be seen very soon.
> 
> In a german Windows environment following encodings are very common and
> the problem is not artificial - Windows_1252, CP850, UTF_8 and ISO8859_1.
> 
> What do you think about this?

I thought Ruby 1.9 tags each string with an encoding? So, if you require a 
file, all contained strings will get tagged with e.g. ISO8859_1 encoding.

You could emulate that, by defining a special method in a library, e.g.

  # yourlib.rb
  class YourLibrary
    def self.encoding
      "a test string".encoding
    end
  end

Now

  require 'yourlib'
  YourLibrary.encoding # => ISO-8859-1
 

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?

Regards,

  Michael



In This Thread