Take the 2-minute tour ×

To get character's Unicode in Ruby 1.9.2, I use ord:

"я".ord       # => 1103     (It's a Russian letter)

How could I get the Unicode in Ruby 1.8.7 ?

share|improve this question
add comment

2 Answers

You could use my backports gem. Running with Ruby 1.8.7 (and option -KU to setup $KCODE for utf-8):

require "rubygems"
require "backports/1.8.7/string/ord"
"я".ord # => 1103
share|improve this answer
add comment
up vote 7 down vote accepted

Well, I found this nice solution:

"я".unpack('U')[0]     # => 1103
share|improve this answer
add comment

Your Answer


