Created
October 26, 2021 07:49
-
-
Save dgorodnichy/6c66bd53c052995763b79a0112350d2a to your computer and use it in GitHub Desktop.
ViewObject example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DateViewObject | |
attr_reader :date | |
def initialize(date) | |
@date = date | |
end | |
def us | |
date.strftime('%m/%d/%y') | |
end | |
def uk | |
date.strftime('%d/%m/%y') | |
end | |
end | |
date = DateViewObject.new(DateTime.now) | |
date.uk # => "24/10/21" | |
date.us # => "10/24/21" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment