# Including common code among multiple web services issue?

**URL:** <https://www.ruby-forum.com/t/including-common-code-among-multiple-web-services-issue/59946>\
**Category:** Rails\
**Created:** [May 8, 2006, 10:02pm UTC](https://www.ruby-forum.com/t/including-common-code-among-multiple-web-services-issue/59946 "2006-05-08T22:02:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![phallstrom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@phallstrom](https://www.ruby-forum.com/u/phallstrom)\
**Post date:** [May 8, 2006, 10:02pm UTC](https://www.ruby-forum.com/t/including-common-code-among-multiple-web-services-issue/59946/1 "2006-05-08T22:02:05Z")

</div>

Hi all -

I’m implementing some web services and every one has at the very least a  
“find\_newer\_than” method.

In my models, I’ve split things up like this and it works great.

* * *

class XyzService \< WebService  
web\_service\_api XyzApi  
… service specific methods go here…  
end

## class WebService \< ActionWebService::Base def find\_newer\_than(created\_at) real\_class.find(:all, :conditions =\> [‘created\_at \>= ?’, TimeZone[‘London’].unadjust(created\_at)]) end … def real\_class Class.const\_get(self.class.to\_s.gsub(/Service$/, ‘’)) end … end

I’d like to do the same for the API’s, but can’t quite get there. If I  
try the same logic as above then when I go to /api/invoke all the  
methods show up as being of the “WebService” class.

Right now I’ve got this and it works. I’d like to move that api\_method  
line into a common file though. Since subclassing the Api’s another  
level didn’t work I’ve tried both require and load, but require doesn’t  
work at all, and load gives me an unknown method error for  
Object#api\_method.

* * *

class XyzApi \< ActionWebService::API::Base

## api\_method :find\_newer\_than, :expects =\> [{:created\_at =\> :datetime}], :returns =\> [[Class.const\_get(self.name.to\_s.gsub(/Api$/, ‘’))]] … end

So, what I really want is to move that code into it’s own file and get  
ruby to simply _insert_ it as is into each of my files and then parse  
it.

Similar to PHP’s include() function.

Suggestions?

THanks!

-philip
