method chaining via symbols

S

snacktime

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
 
J

James Coglan

[Note: parts of this message were removed to make it a legal post.]

2008/9/5 snacktime said:
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



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.
 
J

James Coglan

[Note: parts of this message were removed to make it a legal post.]
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top