0
날짜를 여러 조건과 비교하고 조건을 충족하는 특정 결과를 반환하려고합니다. 나는이 if
및 elsif
문을 좋아하지 않는다 : 여러 조건과 날짜를 비교하려면 어떻게합니까?
은 누구도 서로 다른 조건의 숫자에 날짜를 비교할 수 있었
def ugly_method
if first_active_entitlement.try(:created_at) == nil
"No timestamp on first active entitlement"
elsif first_active_entitlement == nil
"No Active Entitlement"
elsif last_suspended_entitlement == nil
first_time_or_renewal(first_active_entitlement, start_date, end_date)
elsif first_active_entitlement.try(:created_at) > last_suspended_entitlement.try(:suspended_at) && first_active_entitlement.try(:created_at) > start_date && first_active_entitlement.created_at < end_date
"Restart"
else
first_time_or_renewal(first_active_entitlement, start_date, end_date)
end
? 내가 놓친 게 더 쉬울만한 명백한 것이 있습니까?
- 가
first_active_entitlement
- 가
last_suspended_entitlement
이 방법은 메시지를 반환 할 수 있는지 확인 확인하고 어쩌면 플래그는 객체의 존재를 확인 :
실수를 바로 잡으셔서 감사합니다. @theThmMan –
명확히 해 주셔서 감사드립니다. 그것은 지역 사회를 돕는 것입니다. –