# Method chaining via symbols

**URL:** <https://www.ruby-forum.com/t/method-chaining-via-symbols/147776>\
**Category:** Ruby\
**Created:** [September 5, 2008, 11:09am UTC](https://www.ruby-forum.com/t/method-chaining-via-symbols/147776 "2008-09-05T11:09:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snacktime](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@snacktime](https://www.ruby-forum.com/u/snacktime)\
**Post date:** [September 5, 2008, 11:09am UTC](https://www.ruby-forum.com/t/method-chaining-via-symbols/147776/1 "2008-09-05T11:09:46Z")

</div>

If this is too strange just say so. Tonight I was working with a  
rails helper method which accepts several symbols as arguments which  
get turned into method calls. Normally it’s used on activerecord  
objects, but I wanted to make it work on an array of hashes instead.  
That particular approach wouldn’t work without being able to call  
values.first, since some of the hash values were arrays themselves,  
but the rails helper expected a single array.

So anyways I was thinking how it would work if you could do something  
like this:

send(:method1:method2:method3)

Arguments would be passed like normal, and the argument to a chained  
method would be the result of the last method call.

Not sure I even like the idea, just curious if it’s ever been discussed  
before?

Chris

---

<div class="post-metadata">

**Author:** ![snacktime](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@snacktime](https://www.ruby-forum.com/u/snacktime)\
**Post date:** [September 5, 2008, 11:19am UTC](https://www.ruby-forum.com/t/method-chaining-via-symbols/147776/2 "2008-09-05T11:19:22Z")

</div>

2008/9/5 snacktime [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> send(:method1:method2:method3)
> 
> Arguments would be passed like normal, and the argument to a chained  
> method would be the result of the last method call.
> 
> Not sure I even like the idea, just curious if it’s ever been discussed  
> before?
> 
> Chris

Not sure if these are exactly what you’re talking about, but these might  
provide some inspiration:

[http://jicksta.com/posts/the-methodphitamine](http://jicksta.com/posts/the-methodphitamine)

> **[Ruby: Recording Method Calls and Playback With Inject](http://blog.jayfields.com/2008/09/ruby-recording-method-calls-and.html)**
>
> Sometimes you want to call methods on an object, but you want to delay the actual execution of those methods till a later time. For example,...

Both techniques allow you store store chains of method calls and replay  
them  
later on some object.

---

<div class="post-metadata">

**Author:** ![snacktime](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@snacktime](https://www.ruby-forum.com/u/snacktime)\
**Post date:** [September 5, 2008, 11:22am UTC](https://www.ruby-forum.com/t/method-chaining-via-symbols/147776/3 "2008-09-05T11:22:19Z")

</div>

> So anyways I was thinking how it would work if you could do something like  
> this:
> 
> send(:method1:method2:method3)
> 
> Arguments would be passed like normal, and the argument to a chained  
> method would be the result of the last method call.

Actually, could you clarify how this should be expanded? Should it turn  
into:

obj.method3( obj.method2( obj.method1 ) )

or:

obj.method1.method2.method3
