I want all of the dates in the scope of the library to have a common format ("%d.%m.%Y"
) instead of the default ("%Y-%d-%m"
). For now I have come up with 3 different approaches (and I don't like any of them) to accomplish what I want. All of them are represented below in order from most to less painful:
to_s
method for each Date
instance with the necessary format;Date
class with a custom to_s
method.Additional information:
Date
type on each of them;Date
type can vary;The question is as follows:
Is there a better way to handle the issue I am struggling with (and if not, what is the most elegant way to go between the ones that are already represented above)?
Create another module with a refinement to Date::to_s
module MyDate
refine Date do
def to_s
# here goes your implementation of to_s
end
end
end
And then:
class NeedsCustomDateFormat
using MyDate
# All Date instances will have the custom to_s
end