[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: treating an object like a method

Eric Mahurin

5/18/2005 5:38:00 PM


--- Brian Schr?der <ruby.brian@gmail.com> wrote:
> On 18/05/05, Eric Mahurin <eric_mahurin@yahoo.com> wrote:
> > [snip]
> > * klass(*args) : you alias the null method to "new" so that
> > this would be equivalent ot klass.new(*args). I tend to
> forget
> > the ".new" more often than I'd like to admit.
> > [snip]
>
> I don't know if I like this proposal, but in any case I'd
> expect a syntax like:
>
> class A
> def initialize(x)
> @x = x
> end
>
> def self.[](x)
> self.new(x)
> end
>
> def self.()(x)
> self.new(x)
> end
> end
>
> A[12]
> A(12)

That would be fine too. But, if you'd do #2 (object assignment
method), to be consistent, you'd call the method "()=". I kind
of like simply "=" (and "+=", "-=", etc). But, I don't care
about it too much.

BTW, the you'd probably do this in Class instead (to handle it
for all classes):

class Class
alias :[] new # works now
alias :() new # your proposed null method name
alias :@ new # my proposed null method name (like -@ and +@)
end




Yahoo! Mail
Stay connected, organized, and protected. Take the tour:
http://tour.mail.yahoo.com/mai...