From: George Ogata Date: 2004-08-28T04:10:32+09:00 Subject: Re: Question about ? operator for ASCII Barry Sperling writes: > Hello, > I am a nuby and I couldn't find how to get the ASCII value of a > character in a variable. I looked in the Pragmatic Programmer and did this: > > s = "ABC DE." > s.scan( /./ ) do |a| > puts ?a > end > > but only got the ASCII value of the small letter 'a' ( 97 ). What do I > need to do? > Thanks, > Barry Just to add to what others have said: `?' is _not_ an operator (in the sense that `!', `~', etc. are). Rather, `?a' is a literal for the character 'a', just as `10' is the literal for the integer ten, and 1.0 is the literal for the floating point number one-point-oh. It also happens that in ruby these "characters" are really numbers (actually Fixnums), just like in C. This can be demonstrated in irb: irb(main):001:0> ?a => 97 irb(main):002:0> ?a.class => Fixnum irb(main):003:0> 97.class => Fixnum irb(main):004:0> ?a.equal? 97 => true HTH.