From: Eric Mahurin Date: 2005-05-19T02:37:54+09:00 Subject: Re: syntax sugar: treating an object like a method --- Brian Schr�der wrote: > On 18/05/05, Eric Mahurin 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/mailtour.html