From: "Mark J. Reed" Date: 2004-02-01T06:19:53+09:00 Subject: Re: cascading message sends On Sat, Jan 31, 2004 at 11:16:50AM -0800, Paul MG wrote: > In Smalltalk, which Ruby is much like in some ways, you can 'cascade' > message sends. That is, call a bunch of methods on the same object > without naming it explicitly over and over. Eg: > > aCollection add: 5; add: 7; add: 'foo' ! > > calls 'add' on 'aCollection' 3 times, sending 5, 7, and 'foo'. > > Does Ruby have this syntax? Others have mentioned a couple ways to do this generally, but I just wanted to point out that you can do this without any special syntax as long as the methods involved return `self' - which many do, including Array#push: aCollection = [] aCollection.push(5).push(7).push('foo') [5, 7, "foo"] Array#<< does, too, and long chains with it have less syntactic clutter: aCollection << 4 << 3 << 2 [5, 7, "foo", 4, 3, 2] -Mark