Created
April 17, 2020 14:07
-
-
Save minghz/bf3ca50a59d177a70c19e985740a18b9 to your computer and use it in GitHub Desktop.
Three Examples of DTOs in Ruby - Method 1: Simple Immutable Object
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
# | |
# In this example, all required parameters must be provided during | |
# construction of the object, or it will fail to be created. | |
# | |
# The attributes can be read but not modified after object construction. | |
# | |
class BirthdayCard | |
attr_reader :from, :to, :messages | |
def initialize(from:, to:, messages:) | |
@from = from | |
@to = to | |
@messages = messages | |
end | |
end | |
# To create this DTO | |
BirthdayCard.new(from: 'me', | |
to: 'you', | |
messages: ['Wishing you a Happy one!', | |
'You are getting old!']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment