# What is wrong with this initialize method (code example)?

**URL:** <https://www.ruby-forum.com/t/what-is-wrong-with-this-initialize-method-code-example/94671>\
**Category:** Rails\
**Created:** [May 10, 2006, 6:52pm UTC](https://www.ruby-forum.com/t/what-is-wrong-with-this-initialize-method-code-example/94671 "2006-05-10T18:52:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [May 10, 2006, 6:52pm UTC](https://www.ruby-forum.com/t/what-is-wrong-with-this-initialize-method-code-example/94671/1 "2006-05-10T18:52:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [May 10, 2006, 6:58pm UTC](https://www.ruby-forum.com/t/what-is-wrong-with-this-initialize-method-code-example/94671/2 "2006-05-10T18:58:30Z")

</div>

I think you just need to call super, not super.initialize

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [May 10, 2006, 7:17pm UTC](https://www.ruby-forum.com/t/what-is-wrong-with-this-initialize-method-code-example/94671/3 "2006-05-10T19:17:01Z")

</div>

> 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.
