我有以下代码,其中存在一个小错误,在第一个"when"语句评估为true并应该返回"boats"的情况下,case语句返回值"other"。
我已经看了好久了,一定是个小问题。
CATEGORY_CLASSES = {: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
谢谢!
:cars
标签,因此无法返回 "boats"。 - AShelly