Estoy usando el siguiente código para comparar cadenas pero siempre me lleva al else
. ¿Por qué?¿Cómo hago la comparación de cadenas en Ruby?
print("Enter your state abbreviation: ")
state_abbreviation = gets
if state_abbreviation.upcase == "NC"
puts("North Carolina")
elsif state_abbreviation.upcase == "SC"
puts("Sourth Carolina")
elsif state_abbreviation.upcase == "GA"
puts("Georgia")
elsif state_abbreviation.upcase == "FL"
puts("Florida")
elsif state_abbreviation.upcase == "AL"
puts("Alabama")
else
puts("You have enter wrong abbreviation")
end
también he intentado .eql?("string")
pero me da el mismo resultado.
Realmente no sé rubí muy bien, pero ¿por qué tener esta difícil y frágil si-si-si-else estructura? Use un HashMap y, si no obtiene nada, configure el mensaje de error. Esto también ayudaría al nuevo problema al que todos salieron a continuación. – MikeHoss
1. Soy muy nuevo en ruby, ¿por qué no sé si HashMP saldrá de allí? 2. No me gusta el caso, ¿cuándo? – itsaboutcode