global methods in ruby on rails models

前端 未结 3 1010
孤城傲影
孤城傲影 2021-02-04 18:33

I have methods in all of my models that look like this:

def formatted_start_date
  start_date ? start_date.to_s(:date) : nil
end

I would like

3条回答
  •  广开言路
    2021-02-04 19:05

    An answer to your comment: You can extract common code/functionality into modules which you include in a class (I belive that is called mixin?) or you can go for subclasses. I don't think subclass is the way to go when its just common functionality you want to get into your objects, and not a real inheritance situation.

    Take a look at this for more info on modules and Ruby.

提交回复
热议问题