作者:多米音乐_34324431 | 来源:互联网 | 2023-08-04 16:13
Imtryingtoconvertspecialsymbols({W}{B}{U}etc)totheirrespectivecolorsoIwroteaCASE
I'm trying to convert special symbols ({W} {B} {U} etc) to their respective color so I wrote a CASE but I'm thinking a case isn't what I need since it ends as soon as it finds a match.
我正在尝试将特殊符号({B} {U}等)转换成它们各自的颜色,所以我写了一个CASE,但我认为一个CASE不是我需要的,因为它一旦找到匹配就结束了。
print 'Test a Color'
color = gets.chomp
case color
when '{W}'
puts 'White'
when '{R}'
puts 'Red'
when '{G}'
puts 'Green'
when '{U}'
puts 'Blue'
when '{B}'
puts 'Black'
end
{B} gets me Black, {U} gets my Blue. {U}{B} crashes it/returns nothing. How would I go about letting it continue down the list?
{B}让我黑,{}得到我的蓝色。{你} { B }崩溃它/返回。我该如何让它继续下去?
4 个解决方案