Skip to content

Instantly share code, notes, and snippets.

@armandofox
Created May 11, 2021 16:39
Show Gist options
  • Save armandofox/4b333ccb9cbf7f5de75c1ca9d94e7ad6 to your computer and use it in GitHub Desktop.
Save armandofox/4b333ccb9cbf7f5de75c1ca9d94e7ad6 to your computer and use it in GitHub Desktop.
null_object_fix.rb
class Config
def self.emailer
if email_disabled? then NullMailer else
if has_amiko? then Amiko else MailerMonkey end
end
end
end
class NullMailer
def initialize ; end
def send_email_to(*args) ; true ; end
end
def advertise_discount_for_movie
moviegoers = Moviegoer.interested_in(params[:movie_id])
EmailList.new(Config.emailer).send_email_to(moviegoers)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment