Skip to content

Instantly share code, notes, and snippets.

@kotay
Created February 11, 2014 11:09
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 kotay/8932989 to your computer and use it in GitHub Desktop.
Save kotay/8932989 to your computer and use it in GitHub Desktop.
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