Created
March 21, 2010 05:15
-
-
Save JoshCheek/339114 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_name ) | |
plugin = Base::Plugins.const_get plugin_name.capitalize | |
if plugin | |
plugins << plugin_name | |
extend plugin | |
else | |
raise "no such plugin #{plugin_name}" | |
end | |
end | |
module Backward | |
def say(what) | |
super what.reverse | |
end | |
end | |
module Loudness | |
def say(what) | |
super what.upcase | |
end | |
end | |
end | |
end | |
module Base | |
class Server | |
include Plugins | |
def say(what) | |
p "say: #{what}" | |
end | |
end | |
end | |
s = Base::Server.new | |
s.say 'hello world' | |
s.activate 'backward' | |
s.say 'hello world' | |
p s.plugins | |
puts | |
s2 = Base::Server.new | |
s2.say 'hello world' | |
s2.activate 'loudness' | |
s2.say 'hello world' | |
p s2.plugins | |
puts | |
s2.activate 'backward' | |
s2.say 'hello world' | |
p s2.plugins |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment