Created
February 11, 2014 11:09
-
-
Save kotay/8932989 to your computer and use it in GitHub Desktop.
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 Plugins | |
def self.included(base) | |
base.class_eval do | |
include Plugin1 | |
# include IdealPlugin doesn't work | |
# ... | |
hello("from plugins") | |
end | |
end | |
end | |
module Plugin1 | |
def self.included(base) | |
base.class_eval do | |
hello("from plugin 1") | |
end | |
end | |
end | |
module IdealPlugin | |
hello("ideal plugin") | |
end | |
class Greeter | |
def self.hello(name) | |
p "hello #{name}" | |
end | |
include Plugins | |
hello("from greeter") | |
end | |
# I have a class that includes a single plugins module which in turn includes | |
# separate plugin modules. I'd like to be able to call class methods from each plugin | |
# without having to wrap the methods in the `self.included .. class_eval` | |
# Is there anyway I can achieve this nicely?, I'd want to use plugins as per the | |
# IdealPlugin module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment