Created
September 23, 2014 18:05
-
-
Save hale/4d099d20d61e38cdf625 to your computer and use it in GitHub Desktop.
This file contains 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 characters
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