I am working on a project using Rails and have a need to call a certain piece of code from both class and instance methods. I am doing the following now with redundant code in both the class/instance methods. Is there a better way to write this -
module OrderHelper
extend ActiveSupport::Concern
def min_days_to_ship
#to keep it simple, but has other code/logic
3
end
module ClassMethods
def self.min_days_to_ship
#to keep it simple, but has other code/logic
3
end
end
end
class Order < ActiveRecord::Base
include OrderHelper
self.earliest_available
Date.today + OrderHelper::ClassMethods.min_days_to_ship
end
delivery_after_date
self.ordered_date + min_days_to_ship
end
end
Thanks!