What's the opposite of chr() in Ruby?
If String#ord didn't exist in 1.9, it does in 2.0:
"A".ord #=> 65
In Ruby up to and including the 1.8 series, the following will both produce 65 (for ASCII):
puts ?A
'A'[0]
The behavior has changed in Ruby 1.9, both of the above will produce "A" instead. The correct way to do this in Ruby 1.9 is:
'A'[0].ord
Unfortunately, the ord
method doesn't exist in Ruby 1.8.
Try:
'A'.unpack('c')