Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created March 21, 2010 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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