# What is '?' in Ruby?

**URL:** <https://www.ruby-forum.com/t/what-is-in-ruby/184361>\
**Category:** Ruby\
**Created:** [March 1, 2010, 1:30pm UTC](https://www.ruby-forum.com/t/what-is-in-ruby/184361 "2010-03-01T13:30:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghostrifle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f04885/32.png) [@ghostrifle](https://www.ruby-forum.com/u/ghostrifle)\
**Post date:** [March 1, 2010, 1:30pm UTC](https://www.ruby-forum.com/t/what-is-in-ruby/184361/1 "2010-03-01T13:30:58Z")

</div>

Hello!  
To clarify the question I need to say some more.  
I know  
Ruby 1.8 ‘?a’ =\> 97  
Ruby 1.9 ‘?a’ =\> “a”  
Really I would like to where I can get specification of operator,  
keyword, function or something else I do know what is name of ‘?’…  
I have surfed [ruby-lang.org](http://ruby-lang.org) and [ruby-doc.org](http://ruby-doc.org) but can’t find information  
about it. Is it an unofficial something?  
Just a bit here [http://www.ruby-doc.org/docs/ProgrammingRuby/](http://www.ruby-doc.org/docs/ProgrammingRuby/), “Standard  
Types” chapter:  
?a # character code

But it is related to 1.8 version, not for 1.9.  
Please just point to chapter of ruby specification where I can find  
anything about ‘?’ if it is. And are there methods which helps to know  
what is ‘?’?

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![ghostrifle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f04885/32.png) [@ghostrifle](https://www.ruby-forum.com/u/ghostrifle)\
**Post date:** [March 1, 2010, 3:15pm UTC](https://www.ruby-forum.com/t/what-is-in-ruby/184361/2 "2010-03-01T15:15:11Z")

</div>

Alexander Bubnov wrote:

> I know  
> Ruby 1.8 ‘?a’ =\> 97  
> Ruby 1.9 ‘?a’ =\> “a”

It’s a character literal - but in 1.9 a character is a one-character  
string (possibly multiple bytes) rather than an Integer for a single  
byte in 1.8.

You’ll see the same difference with “a”[0]

> Really I would like to where I can get specification of operator,  
> keyword, function or something else I do know what is name of ‘?’…

For 1.8 (actually 1.6.8 🙂

[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut\_stdtypes.html](http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_stdtypes.html)

“You can also get the integer value corresponding to an ASCII character  
or escape sequence by preceding it with a question mark”

For 1.9: you have to buy the more recent version of this book.

> Please just point to chapter of ruby specification

Please point me to any ruby specification 🙂

Actually, there is a project which is attempting to create a  
specification of Ruby for standardisation; it was linked to in this  
mailing list within the last few days. However it’s using 1.8.7 as it’s  
starting point, on the grounds that 1.9 is still a moving target.

I attempted to document strings in 1.9, but only got as far as  
documenting about 200 behaviours.

> <https://github.com/candlerb/string19/blob/master/string19.rb>

---

<div class="post-metadata">

**Author:** ![ghostrifle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f04885/32.png) [@ghostrifle](https://www.ruby-forum.com/u/ghostrifle)\
**Post date:** [March 1, 2010, 3:22pm UTC](https://www.ruby-forum.com/t/what-is-in-ruby/184361/3 "2010-03-01T15:22:22Z")

</div>

On Mar 1, 2010, at 1:31 PM, Alexander Bubnov wrote:

> Types" chapter:  
> ?a # character code
> 
> But it is related to 1.8 version, not for 1.9.  
> Please just point to chapter of ruby specification where I can find  
> anything about ‘?’ if it is. And are there methods which helps to know  
> what is ‘?’?

Ruby 1.8 sees strings as a sequence of bytes. So

“a”[0] #=\> 97

yields 97 (because 97 is the value representing the character a in an  
ASCII-String). If you want to compare this to some character, you need  
the character code of “a” (because no one wants to have an ASCII-Table  
next to them when programming). ?a gives you the character code of a. So

“a”[0] == ?a #=\> true  
“a”[0] == “a” #=\> false

Now, things have changed in the String world in Ruby 1.9. Strings now  
know their encoding and return charactes instead of codepoints when  
accessing single characters.

“a”[0] #=\> “a”

To make sure that legacy applications do not break, ?a will now return  
“a”, so now the behaviour is as follows:

“a”[0] == ?a #=\> true  
“a”[0] == “a” #=\> true

Regards,  
Florian G.

---

<div class="post-metadata">

**Author:** ![ghostrifle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f04885/32.png) [@ghostrifle](https://www.ruby-forum.com/u/ghostrifle)\
**Post date:** [March 1, 2010, 6:40pm UTC](https://www.ruby-forum.com/t/what-is-in-ruby/184361/4 "2010-03-01T18:40:29Z")

</div>

Florian G. wrote:

> On Mar 1, 2010, at 1:31 PM, Alexander Bubnov wrote:
> 
> Ruby 1.8 sees strings as a sequence of bytes. So
> 
> “a”[0] #=\> 97
> 
> yields 97 (because 97 is the value representing the character a in an  
> ASCII-String). If you want to compare this to some character, you need  
> the character code of “a” (because no one wants to have an ASCII-Table  
> next to them when programming). ?a gives you the character code of a. So
> 
> “a”[0] == ?a #=\> true  
> “a”[0] == “a” #=\> false
> 
> Now, things have changed in the String world in Ruby 1.9. Strings now  
> know their encoding and return charactes instead of codepoints when  
> accessing single characters.
> 
> “a”[0] #=\> “a”
> 
> To make sure that legacy applications do not break, ?a will now return  
> “a”, so now the behaviour is as follows:
> 
> “a”[0] == ?a #=\> true  
> “a”[0] == “a” #=\> true
> 
> Regards,  
> Florian G.

Thank you! Have you ever see something about ‘?’ in specification of  
ruby1.9? If so can you please point to that doc. Unfortunately I cannot  
find anything about it but I would like to know it because, for example,  
in ruby1.10 it can be changed in once day.

---

<div class="post-metadata">

**Author:** ![ghostrifle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f04885/32.png) [@ghostrifle](https://www.ruby-forum.com/u/ghostrifle)\
**Post date:** [March 1, 2010, 6:43pm UTC](https://www.ruby-forum.com/t/what-is-in-ruby/184361/5 "2010-03-01T18:43:21Z")

</div>

> Thank you! Have you ever see something about ‘?’ in specification of  
> ruby1.9? If so can you please point to that doc. Unfortunately I cannot  
> find anything about it but I would like to know it because, for example,  
> in ruby1.10 it can be changed in once day.

Many thanks to all!  
I am sorry I did not see post about documentation!  
Now it is clear!
