Skip to content

Instantly share code, notes, and snippets.

@ka8725
Created April 12, 2020 00:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ka8725/4fa4e94b059a9b1f7c4fe5393fa7e850 to your computer and use it in GitHub Desktop.
Save ka8725/4fa4e94b059a9b1f7c4fe5393fa7e850 to your computer and use it in GitHub Desktop.
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