"A cascade sends multiple messages to the same receiver"

Hi, In smalltalk this is possible.

As far as I know ruby has no direct way to support cascading method
calls.

object.method1().method2() # would not work as method1() would not
return self

Then I was thinking, perhaps with a different syntax:

object.(method1|method2)

Could return an array.

Smalltalk has something like this:

"If a series of messages are sent to the same receiver, they can also be
written as a cascade with individual messages separated by semicolons:"

Smalltalk Code:

  Window new
    label: 'Hello';
    open

"This rewrite of the earlier example as a single expression avoids the
need to store the new window in a temporary variable. According to the
usual precedence rules, the unary message "new" is sent first, and then
"label:" and "open" are sent to the answer of "new"."

This all works without one having to create a variable where Window.new
is stored.

In Pseudo-Ruby this could look like:

Window.new.label('Hello').open # but of course this would not work

-- 
Posted via http://www.ruby-forum.com/.