我必須創建邏輯來設置基於多個條件的一天的狀態。我從創建多個if else語句開始,但它感覺不對。請幫助正確的方法。在軌道模型中簡化多個if else條件
def set_status_of_day(late_policy,early_departure_policy)
if late_policy.warning_on_late == "Half Day" && early_departure_policy.warning_on_late == "Half Day"
self.status_of_day = "Absent"
elsif late_policy.warning_on_late == "Half Day" && early_departure_policy.warning_on_late == "Present"
self.status_of_day = "Half Day"
elsif late_policy.warning_on_late == "Half Day" && early_departure_policy.warning_on_late == "Early Departure"
self.status_of_day = "Half Day"
elsif late_policy.warning_on_late == "Late" && early_departure_policy.warning_on_late == "Early Departure"
self.status_of_day = "Half Day"
elsif late_policy.warning_on_late == "Present" && early_departure_policy.warning_on_late == "Present"
self.status_of_day = "Present"
.
.
.
.
.
.
.
end
end
感謝
我不知道我們能做到這一點還有:o –
我建議你添加一個'時/ then'條款,既要完成(沒有'...')並說明一個有用的結構:當[[半天],[現在]],[「半天」,「早出發」],[「半天」,「晚」], –