We were inconsistent on this one. I consider it particularly useful when a method starts with a `return` statement. In other cases, we probably shouldn't have a guard rule in the middle of a method in any case, but that's a different refactoring.
16 lines
426 B
Ruby
16 lines
426 B
Ruby
module ActiveModel::Dates
|
|
def parse_date(field, attrs)
|
|
year, month, day = attrs["#{field}(1i)"],
|
|
attrs["#{field}(2i)"],
|
|
attrs["#{field}(3i)"]
|
|
|
|
return nil unless day.present? && month.present? && year.present?
|
|
|
|
Date.new(year.to_i, month.to_i, day.to_i)
|
|
end
|
|
|
|
def remove_date(field, attrs)
|
|
attrs.except("#{field}(1i)", "#{field}(2i)", "#{field}(3i)")
|
|
end
|
|
end
|