Bohdan
Bohdan

Reputation: 8408

what is "?" in ruby

Ruby 1.9

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

Ruby 1.8.6

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

what does "?" mean ?

Upvotes: 7

Views: 813

Answers (3)

Lindydancer
Lindydancer

Reputation: 26114

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.

Upvotes: 11

Ben
Ben

Reputation: 6965

ruby-1.9.2-p0 > ?c == "c"
 => true 

Upvotes: -2

Michael Kohl
Michael Kohl

Reputation: 66837

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"]

Upvotes: 7

Related Questions