What does the question mark operator mean in Ruby?

It is a code style convention; it indicates that a method returns a boolean value.

The question mark is a valid character at the end of a method name.


Also note ? along with a character, will return the ASCII character code for A

For example:

?F # => will return 70

Alternately in ruby 1.8 you can do:

"F"[0]

or in ruby 1.9:

"F".ord

Also notice that ?F will return the string "F", so in order to make the code shorter, you can also use ?F.ord in Ruby 1.9 to get the same result as "F".ord.


It's a convention in Ruby that methods that return boolean values end in a question mark. There's no more significance to it than that.

Tags:

Ruby