Ho il seguente codice con un piccolo bug in esso, l'istruzione case restituisce il valore "altro" anche se la prima istruzione "when" è vera e deve restituire "boats".Dichiarazione caso breve rubino usando include? Non funziona
Sono stato a guardare questo per secoli, deve essere qualcosa di piccolo.
CATEGORIES = {:boats => [1, 2, 3, 4, 5, 6],
:houses => [7, 8, 9, 10],
:other => [11,12,13,14,15,16]
}
category_id = 1
category = case category_id
when CATEGORY_CLASSES[:boats].include?(category_id); "boats"
when CATEGORY_CLASSES[:houses].include?(category_id); "houses"
else "other"
end
Grazie!
Non c'è ': etichetta cars' nel vostro hash. Quindi è impossibile restituire "barche" – AShelly