From: Josh Cheek Date: 2010-07-29T21:50:09+09:00 Subject: Re: hash key (?) --0016e6ddab47503fdb048c86151e Content-Type: text/plain; charset=ISO-8859-1 On Thu, Jul 29, 2010 at 6:59 AM, Brent Clark wrote: > Hiya > > Im going through the Ruby Cookbook. > > On page 51, there is the following example > > letter = { ?v => 'aeiou', ?c => 'xyz' } > > My question is, what does the key ?v do or mean. > > Kind Regards > Brent Clark > > In earlier versions of Ruby, prefixing a character with a question mark was sort of a literal for a given character. I just checked irb for 1.8.6 and 1.8.7, ?v would return 118, which is the ascii value of the character v, and in 1.9.1 it returned "v" the one character String. Another place you can see this shift take place is in String#[] where you might say "vat"[0] in 1.8 you would get 118, and in 1.9 you would get "v" A more idiomatic alternative would probably be to use symbols as hash keys. letter = { :vowels => 'aeiou' , :consonants => 'xyz' } (I don't have the book, I'm guessing as to what ?v and ?c are supposed to mean) --0016e6ddab47503fdb048c86151e--