When you do ?a in ruby 1.8.7 you used to get the ASCII character of ‘a’
in ruby 1.9.2 this code returns
> ?a
> "a"
What is the significance of this, and what does the output in 1.9.2 mean
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.
In Ruby 1.8
"foo"[0]returned the character code at index 0 instead of the character string at index 0. As part of support for international strings with various encodings (instead of as an array of bytes), Ruby 1.9 changed this behavior to return the single-character string at the specified index.Along with this change,
?awas changed to evaluate as a single-character string as well. Presumably this was so that libraries with code like this……would continue to work. If you want character code value for the first character of a string, use
String#ord:For a lot more answer, see this stackoverflow question.