On Fri, Feb 25, 2011 at 3:42 PM, Gary Wright <gwtmp01 / mac.com> wrote:
>
> On Feb 25, 2011, at 4:52 AM, Martin J. D=FCrst wrote:
>
>> string.force_encoding(ENCODING::BINARY).slice almost does what you want,=
 very efficiently. The problem is that the string will then be marked as BI=
NARY. This can be set back, but it may affect operations that run in parall=
el. To expand on this, something like
>
> Isn't any manipulation of a string via two threads simultaneously already=
 not thread safe?
>
> That is to say, toggling the encoding doesn't make the situation any wors=
e than it is with String#slice all by itself.

No, the issue is that String#force_encoding mutates the string, but
String#slice does not.

str =3D "Hello World"
 =3D> "Hello World"
 > str.slice(4,4)
 =3D> "o Wo"
 > str
 =3D> "Hello World"




--=20
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale