I came across this piece of ruby code:
str[-1]==??
What is the double question mark all about? Never seen that before.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Ruby 1.8 has a ?-prefix syntax that turns a character into its ASCII code value. For example,
?ais the ASCII value for the lettera(or 97). The double question mark you see is really just the number63(or the ASCII value for?).To convert back, you can use the
chrmethod:In Ruby 1.9, the
?asyntax returns the character itself (as does the square bracket syntax on strings):