我想從我的Case語句中返回一個值,我需要執行多行代碼,所以「then」對我不起作用。使用Return可以退出Case語句所在的函數。是否有一個關鍵字能夠幫助我的代碼清楚地意識到我正在返回的內容,而不會在最後一行中添加值?在Ruby Switch中返回命令?
complexity = case(scale)
when "gtp"
x = [various lines of code]
x = [various lines of code]
10
when "preSi"
x = [various lines of code]
x = [various lines of code]
30
when "postSi"
x = [various lines of code]
x = [various lines of code]
40
else
error"Scale not recognized: #{scale.to_s}"
end
那麼爲什麼不直接使用'與任何/無論你正在返回的東西return'關鍵字? – kiddorails
「return」退出我正在使用這個case語句的函數。 –