From: "Iñaki Baz Castillo" Date: 2009-07-22T06:05:18+09:00 Subject: Re: Simple problem with Regular Expression El Martes, 21 de Julio de 2009, Max Norman escribió: > 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 Ruby code must be beautiful: ---------------------------------- fruit = gets.chomp.downcase case fruit when "orange" color = "orange" when "apple" color = "green" when "banana" color = "yellow" else color = "unknown" end if %w{a e i o u}.include?(fruit[0]) puts "An #{fruit} is #{color}." else puts "A #{fruit} is #{color}." end ----------------------------------- :) PS: Just valid for 1.9 due to the usage of "fruit[0]". -- Iñaki Baz Castillo