From: Joel VanderWerf Date: 2008-03-28T05:43:48+09:00 Subject: Re: pypes Martin DeMello wrote: > On Thu, Mar 27, 2008 at 11:33 AM, Dave Thomas wrote: >> http://pragdave.blogs.pragprog.com/pragdave/2007/12/pipelines-using.html >> http://pragdave.blogs.pragprog.com/pragdave/2008/01/pipelines-using.html > > Tangentially, why did the trick of defining methods with the same name > as classes, to delegate to Class.new, fall out of favour? > > tripler = Transformer.new {|val| val * 3} > > would read more nicely as > > tripler = Transformer {|val| val * 3} > > with def Transformer(x); Transformer.new(x); end > > I remember it being a commoner practice a few years ago. > > martin It looks like a typo when there is no method name after (what looks like) a constant name. There's also the cognitive load of deciding whether "Transformer.meth" is "send :meth to the result of method Transformer()" or "send :meth to the value of constant Transformer". My brain knows it is the latter, but my eyes don't. class T def self.meth; "T.meth" end def meth; "T#meth" end end def T; T.new; end p T.meth p T().meth p T.new.meth Quick, which one(s) are calling the class method, T#meth. But maybe that's just me. As long as we're playing in the global space, I'd define a lower case method, #transformer. Saves a keystroke, too. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407