From: Brian Candler on
James Edward Gray II wrote:
> On Apr 18, 2010, at 4:22 AM, Brian Candler wrote:
>
>> One of the joys of ruby 1.9 is that the same program run on two
>> different machines can behave differently. That's even if the two
>> machines have identical versions of ruby and OS *and* you are feeding in
>> the same input data.
>
> I'm pretty sure that's true with Ruby 1.8 as well. For example, don't
> the encodings available to iconv vary depending on the platform?

Perhaps, but I was talking about an identical platform, O/S, and
installation of ruby - but different configured locale (such as LANG,
LC_CTYPE or LC_ALL environment variables)

Unless you write your ruby script defensively, it will behave
differently dependent on those environment settings when everything else
is identical.
--
Posted via http://www.ruby-forum.com/.

From: James Edward Gray II on
On Apr 18, 2010, at 12:14 PM, Brian Candler wrote:

> James Edward Gray II wrote:
>> On Apr 18, 2010, at 4:22 AM, Brian Candler wrote:
>>
>>> One of the joys of ruby 1.9 is that the same program run on two
>>> different machines can behave differently. That's even if the two
>>> machines have identical versions of ruby and OS *and* you are feeding in
>>> the same input data.
>>
>> I'm pretty sure that's true with Ruby 1.8 as well. For example, don't
>> the encodings available to iconv vary depending on the platform?
>
> Perhaps, but I was talking about an identical platform, O/S, and
> installation of ruby - but different configured locale (such as LANG,
> LC_CTYPE or LC_ALL environment variables)

So your main complaint is that Ruby honors the settings of your environment?

James Edward Gray II

From: Benoit Daloze on
[Note: parts of this message were removed to make it a legal post.]

On 18 April 2010 22:17, James Edward Gray II <james(a)graysoftinc.com> wrote:

>
> So your main complaint is that Ruby honors the settings of your
> environment?
>
> James Edward Gray II
>
> Beautiful that one :D (couldn't get a cool answer so I waited somebody else
answer)

Yeah, I think it's normal it saves in the encoding depending on the
environment.
And if you want something that doesn't depend on the environment there is
many possibilities.

The easiest with File: File.open("myfile.ext", "w:UTF-8")

From: Brian Candler on
Benoit Daloze wrote:
> The easiest with File: File.open("myfile.ext", "w:UTF-8")

This is a poor example of the point in question, although a good example
of how hard ruby 1.9 is to understand.

In fact: the default external encoding is nil for files opened for
write, and does not depend on the environment at all. That is,

File.open("myfile.ext","w") { |f| f.puts str }

just outputs whatever bytes are in str, without meddling with them.
Whereas

File.open("myfile.ext","w:UTF-8") { |f| f.puts str}

will attempt to re-encode str from its current encoding to UTF-8, and
may raise an exception if it cannot do so.

So if you want to write programs which don't crash, the first is
arguably better.

The rules for *reading* from files are completely different, and indeed
"r:UTF-8" is the right thing to do if you are reading from a file which
contains UTF-8 text and you don't want this to be affected by
environment variable magic.
--
Posted via http://www.ruby-forum.com/.

From: botp on
On Mon, Apr 19, 2010 at 3:42 PM, Brian Candler <b.candler(a)pobox.com> wrote:
> ... File.open("myfile.ext","w:UTF-8") { |f| f.puts str}
>
> will attempt to re-encode str from its current encoding to UTF-8, and
> may raise an exception if it cannot do so.

good

> So if you want to write programs which don't crash, the first is
> arguably better.

we disagree there but what do you mean by "crash"?

best regards -botp