I've been thinking a bit and I think the easiest solution would be something like this:

```
s = self.class.allocate
str = %{"#{transform(Rubinius::CType::Printed, false).force_encoding(Encoding::US_ASCII)}"}
str += ".force_encoding(\"#{encoding}\")" unless encoding.ascii_compatible?
s.replace(str)
```

You seem to have added a lot of extra .force_encoding calls that seem unnecessary to me.