What is '?' in Ruby?

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 and 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/, “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.

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 :slight_smile:

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 :slight_smile:

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.

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.

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.

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!