ruby - What does the unary question mark (?) operator do? -


i saw operator in haml code. wonder for.

i see following works:

> ?{ => "{"  > ?\s => " "  > ?a => "a"  

and doesn't work:

> ?ab syntaxerror: (irb):4: syntax error, unexpected '?' 

so suppose takes character argument , returns string character.

questions:

  1. what operator do?
  2. when should 1 use it?
  3. if creates one-character string, why included in language? doesn't break language orthogonality? benefit?

it returns single character string. shortest way write single-character string literal. use when want define lot of single-character strings. heritage ruby <1.9, used return ascii code character. don't understand mean "break language orthogonality".


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Socket.connect doesn't throw exception in Android -

iphone - How do I keep MDScrollView from truncating my row headers and making my cells look bad? -