Skip to content

Instantly share code, notes, and snippets.

@hale
Created September 23, 2014 18:05
Show Gist options
  • Save hale/4d099d20d61e38cdf625 to your computer and use it in GitHub Desktop.
Save hale/4d099d20d61e38cdf625 to your computer and use it in GitHub Desktop.
class NotOnTheListError < StandardError; end
module Security
module Bouncer
THE_LIST = %w(john disco_stu)
def enter(name)
unless THE_LIST.include?(name)
raise NotOnTheListError.new("Sorry #{name}, you're not on the list")
end
puts "Hey #{name}, come on through."
super(name)
end
end
def self.prepended(base)
class << base
prepend Bouncer
end
end
end
module Club
prepend Security
def self.enter(name)
puts "+#{name}"
end
end
def club_simulation
%w(john amy disco_stu).each do |name|
begin
Club.enter name
rescue NotOnTheListError => e
puts e.message
end
end
end
club_simulation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment