From: Max Norman Date: 2009-07-22T05:53:09+09:00 Subject: Simple problem with Regular Expression This simple application is an extension of an exercise from Peter Cooper's 'Beginning Ruby, from Novice to Professional.' Its purpose is simple: to collect the name of a fruit and print a sentence describing the fruits name and its color. I've just learned of regular expressions, so I've introduced an 'if' statement that modifies the sentence to suit a name that begins with a vowel, replacing 'a' with 'an.' Unfortunately, this feature doesn't seem to work. The program prints the sentence, but doesn't change it if the word begins with a vowel. Here is the code: fruit = gets.chomp.downcase if fruit == "orange" color = "orange" elsif fruit == "apple" color = "green" elsif fruit == "banana" color = "yellow" else color = "unknown" end fruit.scan(/^./) do |first| if first == 'a' || first == 'e' || first = 'i' || first = 'o' || first = 'u' puts "An #{fruit} is #{color}." else puts "A #{fruit} is #{color}." end end -- Posted via http://www.ruby-forum.com/.