Answer the question
In order to leave comments, you need to log in
Codeclimate rails Similar code: how to optimize?
I decided to start using codeclimate in one of my projects. In the entire project, he found only 1 "darling"
def delivery_method=(deliver)
unless product.shop.delivery_methods.include? deliver
raise ArgumentError.new('This product does not contain delivery method')
end
self.delivery_method_id = deliver.id if deliver.kind_of?(DeliveryMethod)
end
def payment_method=(payment)
unless product.shop.payment_methods.include? payment
raise ArgumentError.new('This product does not contain payment method')
end
self.payment_method_id = payment.id if payment.kind_of?(PaymentMethod)
end
Answer the question
In order to leave comments, you need to log in
def method=(type, object)
unless product.shop.send("#{type}_methods").include?(object)
raise ArgumentError.new('This product does not contain #{type} method')
end
self.send("#{type}_method_id}=", object.id) if object.kind_of?("#{type.capitalize}Method".constantize)
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question