# Dynamic method delegation through polymorphic association

**URL:** <https://www.ruby-forum.com/t/dynamic-method-delegation-through-polymorphic-association/175323>\
**Category:** Rails\
**Created:** [September 11, 2009, 9:55am UTC](https://www.ruby-forum.com/t/dynamic-method-delegation-through-polymorphic-association/175323 "2009-09-11T09:55:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![disturb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@disturb](https://www.ruby-forum.com/u/disturb)\
**Post date:** [September 11, 2009, 9:55am UTC](https://www.ruby-forum.com/t/dynamic-method-delegation-through-polymorphic-association/175323/1 "2009-09-11T09:55:38Z")

</div>

This is too much for my ruby skills level…  
Since i can’t use multiple tables inheritance, i’ve been trying to  
implement some shared behaviour and state in an AR ‘wrapper’ model  
that delegates method calls to an associated business objects through  
a polymorphic association

class CoreEntity \< ActiveRecord::Base  
belongs\_to :business, :polymorphic =\> true

end

class FirstBusinessEntity \< ActiveRecord::Base  
has\_one :core\_entity, :as =\> :business

def some\_business\_method  
return true  
end  
end

in the CoreEntity class, i can hard code :  
delegate :some\_business\_method, :to =\> :business  
and it works fine, but as soon as i’ll need to associate a different  
business entity, i’m screwed.

Can I dynamically set the delegate parameters, depending on the  
associated business object ?  
Or am i looking at this the wrong way ?

cheers
