Created
March 21, 2010 02:07
-
-
Save chikamichi/339025 to your computer and use it in GitHub Desktop.
plugins system: standalone
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 | |
class Server | |
def blabla(argument) | |
@config ||= "default" | |
if @config == "default" | |
p "Server says: #{argument}" | |
end | |
puts "config: #{@config}" | |
end | |
end | |
end | |
module Base | |
module Plugins | |
module Something | |
def blabla(argument) | |
@config ||= "Something" | |
if @config == "Something" | |
p "Server (Somethinged) says: #{argument}" | |
end | |
super | |
end | |
end | |
end | |
end | |
g = Base::Server.new | |
puts g.instance_eval("class << self; self; end").ancestors.inspect | |
puts | |
g.blabla("hello world") | |
puts | |
puts "---" | |
puts | |
g.extend(Base::Plugins::Something) | |
puts g.instance_eval("class << self; self; end").ancestors.inspect | |
puts | |
g.blabla("hello world from Something") | |
puts | |
puts "---" | |
puts | |
module Base | |
module Plugins | |
module SomethingElse | |
def blabla(*arguments) | |
@config = "SomethingElse" | |
puts arguments.join " " | |
super arguments.join " " | |
end | |
end | |
end | |
end | |
g.extend(Base::Plugins::SomethingElse) | |
puts g.instance_eval("class << self; self; end").ancestors.inspect | |
puts | |
g.blabla("Hello", "World", "From", "Something", "Else") | |
puts | |
# => | |
# [Base::Server, Object, Kernel] | |
# "Server says: hello world" | |
# config: default | |
# --- | |
# [Base::Plugins::Something, Base::Server, Object, Kernel] | |
# "Server says: hello world from Something" | |
# config: default | |
# --- | |
# [Base::Plugins::SomethingElse, Base::Plugins::Something, Base::Server, Object, Kernel] | |
# Hello World From Something Else | |
# config: SomethingElse |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment