Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created March 21, 2010 04:56
Show Gist options
  • Save JoshCheek/339101 to your computer and use it in GitHub Desktop.
Save JoshCheek/339101 to your computer and use it in GitHub Desktop.
# 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