Skip to content

Instantly share code, notes, and snippets.

@chikamichi
Created March 21, 2010 06:20
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 chikamichi/339129 to your computer and use it in GitHub Desktop.
Save chikamichi/339129 to your computer and use it in GitHub Desktop.
plugins
module Base
module Plugins
def self.plugins
@plugins ||= []
end
def self.activate plugin_name
begin
plugin = Base::Plugins.const_get(plugin_name.capitalize)
rescue
raise "No such plugin \"#{plugin_name.capitalize}\""
end
plugins << plugin_name
plugin.unpack if plugin.respond_to?(:unpack)
end
end
end
module Base
module Plugins
module Backward
def self.unpack
puts "Unpacking #{self}"
Base::Speaker.send :include, SpeakerRedef
#Base::Speaker.send :extend, SpeakerRedef
end
module SpeakerRedef
#def self.extended(receiver)
#receiver.send :include, InstanceMethods
#end
#module InstanceMethods
def say(what)
super what.reverse
end
#end
end
end
end
end
module Base
class Speaker
def initialize
puts instance_eval("class << self; self; end").ancestors.inspect
end
def say(what)
p "say: #{what}"
end
end
class Server
s = Base::Speaker.new
s.say 'hello world'
include Plugins
Base::Plugins.activate 'backward'
s2 = Base::Speaker.new
s.say 'hello world'
s2.say 'hello world'
end
end
Base::Server.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment