# Rails plugins?

**URL:** <https://www.ruby-forum.com/t/rails-plugins/176142>\
**Category:** Rails\
**Created:** [September 25, 2009, 8:03am UTC](https://www.ruby-forum.com/t/rails-plugins/176142 "2009-09-25T08:03:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastian\_von\_Conra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@Sebastian\_von\_Conra](https://www.ruby-forum.com/u/Sebastian_von_Conra)\
**Post date:** [September 25, 2009, 8:03am UTC](https://www.ruby-forum.com/t/rails-plugins/176142/1 "2009-09-25T08:03:04Z")

</div>

Hi everyone,

I’m trying to set up a plugin structure where I have a main module  
(for argument’s sake called “Abc”), which I want to be able to access  
in my controllers. So far, so good. I can invoke Abc.method\_name  
without difficulties.

The problems start once I the next part of my plugin: I want to extend  
Abc with another module or class, either Foo or Bar, with a method  
such as:

Abc.choose\_child(‘Foo’)

The code I currently have is:

/vendors/plugin/my\_plugin/lib/abc.rb

module ABC  
def self.choose\_child(child)  
require “children/” + child  
send :include, child.constantize  
end  
end  
ActionController::Base.send :include, SOAPHandler

/vendors/plugin/my\_plugin/lib/children/foo.rb

module Foo  
def self.foobar  
return “hello from Foo”  
end  
end

/vendors/plugin/my\_plugin/lib/children/bar.rb

module Bar  
def self.foobar  
return “hello from Bar”  
end  
end

Then, I want to be able to–in my controllers–do Abc.foobar, which  
would return either “hello from Foo” or “hello from Bar” depending on  
which one I loaded with choose\_child.

This is the loose implementation, anyway–feel free to point out a  
better structure.

Any help would be appreciated.

Best regards,  
Sebastian
