Created
September 23, 2014 17:58
-
-
Save hale/9a7907bf07bec3cd983a 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
module Security | |
module Bouncer | |
THE_LIST = %w(john) | |
def enter(name) | |
raise "Sorry #{name}, you're not on the list" unless THE_LIST.include?(name) | |
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} has entered the building" | |
end | |
end | |
class ClubSimulator | |
@queue = %w(john john amy john) | |
def self.run | |
@queue.each do |name| | |
begin | |
Club.enter name | |
rescue Exception => e | |
puts e.message | |
end | |
end | |
end | |
end | |
ClubSimulator.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment