Created
April 12, 2020 00:55
-
-
Save ka8725/4fa4e94b059a9b1f7c4fe5393fa7e850 to your computer and use it in GitHub Desktop.
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 SMSGateway | |
# @param phone [String] | |
# @param message [String] | |
def self.send_message(phone, message) | |
puts "Hello #{phone}, #{message}" | |
end | |
end | |
User = Struct.new(:phone, :active) | |
class MessageService | |
# @param message [String] | |
# @param recipients [Array<User>] | |
def broadcast(message, recipients) | |
recipients.each(&send_message(message)) | |
end | |
private | |
def send_message(message) | |
->(recipient) { SMSGateway.send_message(recipient.phone, message) if recipient.active} | |
end | |
end | |
recipients = [ | |
User.new('+12345654547', true), | |
User.new('+12345654548', false), | |
] | |
service = MessageService.new | |
service.broadcast('have a good day!', recipients) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment