Mark Slagell <ms / iastate.edu> wrote:
>Jiangyi Liu wrote:
>> 
>> Hi all,
>> 
>> I met a problem when I tried to write some Ruby code to learn Ruby. The
>> following code just can't work as expected,
>> 
>> "Hello".each_byte { |c|
>>     if c == "o"
>>         print "oh, i got an o!", "\n"
>>     end
>> }
>> 
>> Seems in Ruby, in the comparsion c and "o" is always false. How can I make
>> the above code right? Thanks a lot.
>> 
>> Jiangyi Liu
>
>You're comparing strings to characters, which has to fail.  To specify
>the character o, change "o" to ?o above.

Or test:
  if c.chr == 'o'
(or)
  if c.chr == "o"

These can be handy if you're trying to compare 
with something like a space, and don't want to 
say if c == 32.

Kevin