Created
April 12, 2020 00:55
-
-
Save ka8725/4fa4e94b059a9b1f7c4fe5393fa7e850 to your computer and use it in GitHub Desktop.
Revisions
-
ka8725 created this gist
Apr 12, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ 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)