The c variable already contains the char code!
c
"string".each_byte do |c| puts cend
yields
115116114105110103
puts "string".split('').map(&:ord).to_s
Ruby String provides the codepoints method after 1.9.1.
codepoints
str = 'hello world'str.codepoints.to_a=> [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100] str = "你好世界"str.codepoints.to_a=> [20320, 22909, 19990, 30028]