ruby - refactoring if else statement -
i've tried reading tutorials on refactoring , struggling conditionals. don't want use ternary operator maybe should extracted in method? or there smart way use map?
detail.stated = if value[:stated].blank? nil elsif value[:stated] == "incomplete" nil elsif value[:is_ratio] == "true" value[:stated] == "true" else apply_currency_increment_for_save(value[:stated]) end
if move logic method, can made lot cleaner return
(and keyword arguments):
def stated?(stated:, is_ratio: nil, **) return if stated.blank? || stated == "incomplete" return stated == "true" if is_ratio == "true" apply_currency_increment_for_save(stated) end
then...
detail.stated = stated?(value)
Comments
Post a Comment