Created
March 21, 2010 04:56
-
-
Save JoshCheek/339101 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
# based on http://gist.github.com/339028 | |
module Base | |
module Plugins | |
def plugins | |
@plugins ||= [] | |
end | |
def activate plugin | |
plugins << plugin | |
plugin = Base::Plugins.const_get(plugin.capitalize) | |
plugin.activate(self) if plugin.respond_to?(:activate) | |
end | |
module Backward | |
def self.activate(obj) | |
obj.extend Redefinitions | |
end | |
module Redefinitions | |
def say(what) | |
p "say: #{what.reverse}" | |
end | |
end | |
end | |
module Loudness | |
def self.activate(obj) | |
obj.extend Redefinitions | |
end | |
module Redefinitions | |
def say(what) | |
p "say: #{what.upcase}" | |
end | |
end | |
end | |
end | |
end | |
module Base | |
class Server | |
include Plugins | |
def say(what) | |
p "say: #{what}" | |
@config = "default" | |
end | |
end | |
end | |
s = Base::Server.new | |
s.say 'hello world' | |
s.activate 'backward' | |
s.say 'hello world' | |
puts | |
s2 = Base::Server.new | |
s2.say 'hello world' | |
s2.activate 'loudness' | |
s2.say 'hello world' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment