# Dynamically chain class methods

**URL:** <https://www.ruby-forum.com/t/dynamically-chain-class-methods/174743>\
**Category:** Rails\
**Created:** [September 1, 2009, 3:29pm UTC](https://www.ruby-forum.com/t/dynamically-chain-class-methods/174743 "2009-09-01T15:29:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anderson\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/35a633/32.png) [@Anderson\_M](https://www.ruby-forum.com/u/Anderson_M)\
**Post date:** [September 1, 2009, 3:29pm UTC](https://www.ruby-forum.com/t/dynamically-chain-class-methods/174743/1 "2009-09-01T15:29:22Z")

</div>

Hi all,

I was wondering if it is possible to dynamically chain class methods in  
rails. Suppose there are several optional methods that a class may have,  
I  
want to chain call all the methods that apply to a certain class. Is it  
possible? What is the best approach to do achieve this?

Thanks in advance.

–  
Anderson M.  
[www.aposasopa.com](http://www.aposasopa.com)  
Linux User #419944

2009/8/12 doug [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Anderson\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/35a633/32.png) [@Anderson\_M](https://www.ruby-forum.com/u/Anderson_M)\
**Post date:** [September 1, 2009, 3:29pm UTC](https://www.ruby-forum.com/t/dynamically-chain-class-methods/174743/2 "2009-09-01T15:29:57Z")

</div>

On Sep 1, 11:23 am, Anderson M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi all,
> 
> I was wondering if it is possible to dynamically chain class methods in  
> rails. Suppose there are several optional methods that a class may have, I  
> want to chain call all the methods that apply to a certain class. Is it  
> possible? What is the best approach to do achieve this?

ActiveSupport::Callbacks ?

Fred

---

<div class="post-metadata">

**Author:** ![Anderson\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/35a633/32.png) [@Anderson\_M](https://www.ruby-forum.com/u/Anderson_M)\
**Post date:** [September 2, 2009, 10:43pm UTC](https://www.ruby-forum.com/t/dynamically-chain-class-methods/174743/3 "2009-09-02T22:43:25Z")

</div>

On Tue, Sep 1, 2009 at 6:23 AM, Anderson M.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi all,
> 
> I was wondering if it is possible to dynamically chain class methods in  
> rails. Suppose there are several optional methods that a class may have, I  
> want to chain call all the methods that apply to a certain class. Is it  
> possible? What is the best approach to do achieve this?

ActiveSupport defined Module#alias\_method\_chain which is used  
extensively to do what I think you are asking for.

Googling alias\_method\_chain should fill you in on the details.

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Twitter: [http://twitter.com/RickDeNatale](http://twitter.com/RickDeNatale)  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)
