I am looking to turn the character 'a' into 97 in ruby 1.9.2
Ruby 1.8.7
irb(main):001:0> ?a => 97 Ruby 1.9.2
irb(main):001:0> ?a => "a" I am looking to turn the character 'a' into 97 in ruby 1.9.2
Ruby 1.8.7
irb(main):001:0> ?a => 97 Ruby 1.9.2
irb(main):001:0> ?a => "a" For those, who are looking for the opposite of ord. We have chr
>> "A".ord => 65 >> 65.chr => "A" Note that if you want to write code that is compatible with both Ruby 1.8 and Ruby 1.9, you may want to use String#each_byte like this:
$ irb >> 'a'.each_byte.first => 97 ?a will return the ASCII value of the char a
?a will return the closest thing to a char type Ruby has, which in Ruby 1.9 is a single-character String and in Ruby pre-1.9 is a Fixnum. String#ord (and its dual Integer#chr) is what you want to use.