P
Paul MG
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?
cheers
PMG
--
PS: yes, you can fake it, if you make the method return 'self': you
just chain the methods together. In Smalltalk:
((aCollection add: 5) add: 7) add: 'foo' !
But the ';' operator is needed for the case when the method returns
something other than 'self' - eg for instance, the object just added.
In which case clearly this 'cheat' doesn't work!
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?
cheers
PMG
--
PS: yes, you can fake it, if you make the method return 'self': you
just chain the methods together. In Smalltalk:
((aCollection add: 5) add: 7) add: 'foo' !
But the ';' operator is needed for the case when the method returns
something other than 'self' - eg for instance, the object just added.
In which case clearly this 'cheat' doesn't work!