[Nitro] Concerns over Og mandating the form of initialize

James Britt james_b at neurogami.com
Wed Apr 13 09:45:16 EDT 2005

George Moschovitis wrote:
>>I 'll investigate.
> Not much to investigate:
> ri Class#allocate
> --------------------------------------------------------- Class#allocate
>      class.allocate()   =>   obj
> ------------------------------------------------------------------------
>      Allocates space for a new object of _class_'s class. The returned
>      object must be an instance of _class_.
> so i replaced klass.new with klass.allocate and the initialize method
> is not called.
> the object gets correctly restored by og_read, and there are no
> restirction for your initialize method. What do you think James? I
> think this solves your problem nicely.

Class Foo
  attr_accessors :x, :y
  def initialize( x=nil, y=nil )
    @tstamp = Time.now

  def create_date


Question: If you do not call Foo.new, how is @tstamp initialized to the 
time of creation?

My main point is that 'initialize' is where an object makes sure it is 
starting life on the right foot.  It is the best place to assure that it 
has correct, complete, consistent data.  If you override calling 'new', 
then an object may be created with invalid state.


More information about the Nitro-general mailing list