我的应用程序中有非常简单的方法。我想知道是否有办法让它更短。
def is_enough_words_to_play_game?
if Word.verified.size > 5
true
else
false
end
end
答案 0 :(得分:5)
你可以写:
def is_enough_words_to_play_game?
Word.verified.size > 5
end
因为Word.verified.size > 5
已经返回布尔值。
或恕我直言更可读:
MIN_WORDS_FOR_GAME = 6
def enough_words?
Word.verified.size >= MIN_WORDS_FOR_GAME
end
答案 1 :(得分:1)
我会把它写成
rxString = mySerialPort.ReadExisting();
byte[] bytes = Encoding.ASCII.GetBytes(rxString);
if (bytes.SequenceEqual(new byte[] { (byte0) = 0x95 }))
{
tb_Status.AppendText("Correct Sequence");
}
else
{
tb_Status.AppendText("Incorrect Sequence!!!");
}