Skip to content

Instantly share code, notes, and snippets.

@hale
Created September 23, 2014 17:58
Show Gist options
  • Save hale/9a7907bf07bec3cd983a to your computer and use it in GitHub Desktop.
Save hale/9a7907bf07bec3cd983a to your computer and use it in GitHub Desktop.
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