From: Jiangyi Liu Date: 2000-12-23T19:10:03+09:00 Subject: [ruby-talk:8000] Re: Comparsion Problem? Okay, thank you for your reply. Now I got it. "Keith Weinberg" wrote in message news:3A424075.727CB63C@groupdigital.com... > reply inline. . . > > Dan Schmidt wrote: > > > > "Jiangyi Liu" writes: > > > > | 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 > > | } > > > > In ruby, characters and one-element strings are different types, > > unlike some other languages. > > each_byte is returning exactly that. . . the number associate with each > byte. > As far as I can tell, Ruby doesn't have a "Character" object. You > typically > (conveniently) use one-character strings. > > > > > Try 'if c == ?o' insead. > > I don't think that will work. 'o' is a string just like "o" > > Try this instead [it "splits" the string into an array of strings (each > one character > long) and iterates over them]. > > "hello".split(//).each{|c| > if (c == "o") then > puts "oh, I got an o" > end > } > > or more concisely: > "hello".split(//).each{|c| puts "oh, I got an o" if (c == "o")} > > enjoy Ruby, I do, > /<