Created
March 21, 2010 06:20
-
-
Save chikamichi/339129 to your computer and use it in GitHub Desktop.
plugins
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
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