3
我是Ruby新手。比較實例變量的相等性
class X
attr_accessor :minX, :maxX, :minY, :maxY
def initialize
@minX = 0, @maxX = 4, @minY = 0, @maxY = 4
if @minX == @minY && @maxX == @maxY
# do stuff
else
# not square
end
end
end
這總是進入else子句 - 爲什麼?
是有道理的,一直在做太多的Groovy。 – wulfgarpro
當我從另一種語言切換時,我仍然對這種功能感到困惑:) – NicoSantangelo
我認爲最好的解決方案是「把它們中的每一個放在一個單獨的行中」。根據[Ruby風格指南](https://github.com/bbatsov/ruby-style-guide):「不要使用;將語句和表達式分開,作爲必然結果 - 每行使用一個表達式。」 –