How to get the ascii code for "x"

784 Views Asked by At

I'm in the terminal and I'm running IRB. I'm trying to get the ASCII value of x. I know the value is 120. That's correct right? When I type the following into my terminal this is the response I get:

puts ?x
(output) x

Why isn't it coming up 120?

1

There are 1 best solutions below

0
On

String#ord could be used to get the integer representation of a one-character string:

'x'.ord
# => 120

P.S: use 'x' or "x" instead of ?x.