Method chaining via symbols

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

2008/9/5 snacktime [email protected]

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://blog.jayfields.com/2008/09/ruby-recording-method-calls-and.html

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs