I read from to the docs[1] that string[index] should do the
following: “If passed a single Fixnum, returns the code of the
character at that position.”
This is working as documented with Ruby 1.8.6, but it isn’t with Ruby
1.9.1p129 (on my WinXP machine). Why is this so?
Because you’re looking at the documentation for ruby 1.8, not at that
for ruby
1.9. The documentation for ruby 1.9, which you can find at RDoc Documentation, states that in ruby 1.9,
String#[]
returns the character at the given position, not its code. To obtain the
code
of the character, you can use its ord method: