Kyle Decot Kyle Decot - 8 months ago 38
Ruby Question

String#[] Differences between Ruby 1.8.7 and 1.9.3

I'm attempting to upgrade an old rails 2.x/ruby 1.8.7 application but I'm
running into an issue. I have the string

and in my code
I have something that looks like:


In 1.8.7 this returns the Fixnum
. In ruby 1.9.3 (and newer) however this
returns the String

My question is two part: First, what's happening here, and secondly how can I
get a similar behavior to what's being returned in 1.8.7 in newer versions of

Update #1

As some have suggested I tried
but this however doesn't work (it does work in
though) as it errors with:

NoMethodError: undefined method `[]' for #<Enumerator: "\x80\u0001\u0002\u0004\b\u0010":bytes>


To get the old behavior, use String#getbyte, as in: