[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Syntax sugar: method[](...) => method(...

Yukihiro Matsumoto

6/30/2007 7:18:00 AM

Hi,

In message "Re: Syntax sugar: method[](...) => method(...)"
on Sat, 30 Jun 2007 05:17:27 +0900, "Erwin Abbott" <erwin.abbott@gmail.com> writes:

|Lastly, has there been any mention of allowing function names like so
|in ruby 1.9:
| def logins[] date
| # ...
| end

It is quite difficult since

obj.login[date]

would be ambiguous. We have no way to tell the method name to be
"login[]" or "login".

matz.

1 Answer

Gary Wright

7/9/2007 7:08:00 PM

0


On Jun 30, 2007, at 3:18 AM, Yukihiro Matsumoto wrote:
> In message "Re: Syntax sugar: method[](...) => method(...)"
> on Sat, 30 Jun 2007 05:17:27 +0900, "Erwin Abbott"
> <erwin.abbott@gmail.com> writes:
>
> |Lastly, has there been any mention of allowing function names like so
> |in ruby 1.9:
> | def logins[] date
> | # ...
> | end
>
> It is quite difficult since
>
> obj.login[date]
>
> would be ambiguous. We have no way to tell the method name to be
> "login[]" or "login".

I've wished for the functionality the OP suggested but I understand that
there really isn't much wiggle room in the current Ruby syntax.

This would probably be a headache from a parsing perspective but what
about
something like:

obj.login@[date]

which would be interpreted as calling the method named 'login@[]'.
This is suggestive of the Eiffel array indexing syntax but with the
square
brackets to avoid any ambiguity with instance variables.


Gary Wright