Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is "?" in ruby

Tags:

ruby

Ruby 1.9

irb(main):001:0> ?c
=> "c"

Ruby 1.8.6

 irb(main):001:0> ?c
 => 99

what does "?" mean ?

like image 617
Bohdan Avatar asked Mar 25 '11 17:03

Bohdan


2 Answers

It denotes a "character". In ruby 1.8, this was represented by the ascii-code of the character. In Ruby 1.9, it's a single-character String.

like image 111
Lindydancer Avatar answered Sep 29 '22 12:09

Lindydancer


In 1.8 they give you the ASCII value of a character, in 1.9 they are character literals:

>> RUBY_VERSION #=> "1.8.7"
>> ?a #=> 97 
>> RUBY_VERSION #=> "1.9.2"
>> ?a #=> "a"
>> *[?a..?c] #=> ["a", "b", "c"]
like image 24
Michael Kohl Avatar answered Sep 29 '22 14:09

Michael Kohl