Improvements to `char` in Ruby 1.9

The new version of the Ruby language brings improvements to characters. There is no `char` concept per se (which is fine), but the implementation now makes a lot more sense.

In Ruby 1.8, a char is represented by its ASCII value. The literal character A is the same as 65 and it conversely is exactly the same as the integer number 65. Interesting, but confusing.

In Ruby 1.9 a char is represented by a single-character String. This really makes a lot more sense. The literal character A (you can specify one with ?A in your script) now is exactly the same as the string ‘A’. Makes a lot more sense and I am glad Matz decided to change it.

  1. No comments yet.

  1. No trackbacks yet.