我創建了以下(這是更多的代碼部分,但僅此行是問題):紅寶石錯誤 - 我可以將此塊與{...}轉換成一行嗎?
if number_to_test % divisor == 0 then number_of_divisors+= 1 end
我想與
if number_to_test % divisor == 0 { number_of_divisors+= 1 }
縮短它,但我得到
syntax error, unexpected '{', expecting keyword_then or ';' or '\n'
if number_to_test % divisor == 0 { number_of_divisors+= 1 }
^
syntax error, unexpected '}', expecting keyword_end
我想我可以將長表單改爲{}
你能告訴我正確的語法(如果可能的話)嗎?
也許我只是想做結束塊而不是if語句?
如果你喜歡方法鏈接,你可以做'number_to_test.modulo(divisor).zero?' – 2012-03-05 07:25:48