Reputation: 22415
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"
Upvotes: 43
Views: 43869
Reputation: 1891
For those, who are looking for the opposite of ord
. We have chr
>> "A".ord
=> 65
>> 65.chr
=> "A"
Upvotes: 37
Reputation: 224689
You probably want String#ord
:
% irb
ruby-1.9.2-head > 'a'.ord
=> 97
Upvotes: 69
Reputation: 8866
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
Upvotes: 3