Ruby: Reusing code in instance and class methods -
Text after "
I am working on a project using rail and calling a fixed piece of code in both class and example ways There is a need for I am now in the following class in two class / example ways with redundant code: there is a better way to write it -
module OrderHelper #to keep it simple min_days_to_ship ActiveSupport :: anxiety DEF , But other code / logic 3 end module classmethods def #to self.min_days_to_ship keep it simple, but other code / logic 3 and end and class order & lt; ActiveRecord :: Base included 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
Thank you!
examples and class methods are in this case the min_days_to_ship
are similar, just
module module and
after orderHelper
on expanded orderhelter
See Code> min_days_to_ship
want to be both an example and class method whenever the module is included
d, module classmethods
DRF self.included (Class) Clays. Extend Sprite and
extension of the order holler
class command
Comments
Post a Comment