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