From: Florian Gilcher Date: 2010-03-01T23:21:57+09:00 Subject: Re: What is '?' in Ruby? On Mar 1, 2010, at 1:31 PM, Alexander Bubnov wrote: > 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 '?'? 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 Gilcher