[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: private #initialize

Yukihiro Matsumoto

11/28/2008 8:04:00 AM

Hi,

In message "Re: private #initialize"
on Fri, 28 Nov 2008 10:24:24 +0900, "Robert Dober" <robert.dober@gmail.com> writes:

|On Fri, Nov 28, 2008 at 12:32 AM, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
|
|> #initialize is, by its design, supposed to be called only from within
|> #new to separate per object/class initialization from the #new, thus
|> you don't have to redefine #new. When you need/want to redefine #new,
|> it's a sign of a bad design, I believe.
|I am delivering this code to your judgment
|
|module Immutable
| def new *args, &blk
| o = allocate
| o.send( :initialize, *args, &blk )
| o.freeze
| end
|end

It's far better than normal #new replacement. But it's still not
worth making #initialize public though. Honestly speaking, tasks like
the code you've presented should be solved by AOP or method
combination, which unfortunately Ruby does not have right now.
Maybe in the future.

matz.