I am chasing a bug in my Rails app.  I've tracked it down to something =
in memcache-client.  I'm not the owner of this code but wanted to supply =
a patch to fix it but I have some questions.

The code (in very simple terms) is doing:

1: value =3D Marshal.dump value
2: command =3D "build up a string with various things including =
#{value}"

later, it does:

socket.write(command)

The problem is "build up a string..." is either UTF-8 or US-ASCII but =
value has an encoding of ASCII-8BIT.   So line 2 above raises an =
incompatible character encoding exception.

What would be the best way to solve this?

I could force the encoding of value to UTF-8 (after the marshaling =
statement).  That was my first thought.  But, why is it encoded with 8 =
bit?  I'm wondering if there is a reason for that.

The socket.write could be broken up into

socket.write "build up a string with various things include "
socket.write value

but... socket is going to have an encoding too -- isn't it?

In this particular case, I've set Ruby's internal and external encoding =
to UTF-8.

I'm also wondering if perhaps this isn't a bug with Marshal since it =
says it encodes it to a string.  I would interpret that on the surface =
as encoding it to a string with the current encoding.

I'm using Ruby 1.9.2 p290

Thank you for your time,
pedz