Hi,

On Mon, 13 Oct 2008 05:59:49 +1100, Yukihiro Matsumoto  
<matz / ruby-lang.org> wrote:

>> I'd rather propose, default_internal to be the default target encoding
>> of the String#encode method, so that
>>
>>   str.encode
>>
>> to be equivalent to
>>
>>   str.encode(default_internal)
>>
>> with the optimization tricks you've suggested.
>>
>
> Yes, that is very neat.

I just tried String#encode with no parameter, but I was hoping to just be  
able to say:

	return str.encode

to return a string from a method in the default_internal encoding if it is  
set. Unfortunately, unlike my suggested implementation, it raises an  
exception when default_internal is not set, so I have to say:

	return Encoding.default_internal ? str.encode : str

which isn't really much neater than what I had before:

	return Encoding.default_internal ? str.encode(Encoding.default_internal)  
: str

I guess I can either write my own encode_internal method to handle this,  
but I think it is universally useful for libraries which handle strings,  
where default_internal may or may not be set.

Cheers
Mike