Forum: Ruby on Rails What is wrong with this initialize method (code example)?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Wes G. (Guest)
on 2006-05-10 20:52
Here is my class:

class Document < ActiveRecord::Base

  public
  def initialize
    puts "Called initialize..."
    super.initialize
  end

This generates the following error:

You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occured while evaluating nil.initialize

WTF?

Wes
Vince P. (Guest)
on 2006-05-10 20:58
(Received via mailing list)
I think you just need to call super, not super.initialize
Vince P. (Guest)
on 2006-05-10 21:17
(Received via mailing list)
>From the "programming ruby" book...

Within the body of a method, a call to super acts just like a call to
that
original method, except that the search for a method starts in the
superclass of the object that was found to have the original method.

Explains why you are getting the nil.initialize error.  'super' is like
calling initialize, which returns nil.
This topic is locked and can not be replied to.