# Question about initialize

**URL:** <https://www.ruby-forum.com/t/question-about-initialize/106644>\
**Category:** Ruby\
**Created:** [June 12, 2007, 7:35pm UTC](https://www.ruby-forum.com/t/question-about-initialize/106644 "2007-06-12T19:35:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mschwab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mschwab](https://www.ruby-forum.com/u/mschwab)\
**Post date:** [June 12, 2007, 7:35pm UTC](https://www.ruby-forum.com/t/question-about-initialize/106644/1 "2007-06-12T19:35:43Z")

</div>

Why is the constructor method named initialize? Why not name it new to  
be  
consistent?

Mike S.

---

<div class="post-metadata">

**Author:** ![mschwab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mschwab](https://www.ruby-forum.com/u/mschwab)\
**Post date:** [June 12, 2007, 7:49pm UTC](https://www.ruby-forum.com/t/question-about-initialize/106644/2 "2007-06-12T19:49:16Z")

</div>

On Jun 12, 2007, at 10:34 AM, Mike S. wrote:

> Why is the constructor method named initialize? Why not name it new  
> to be  
> consistent?  
> Typically, :new is a class method, which calls the instantiated  
> object’s :initialize instance method, if one is available, with the  
> parameters passed to :new.  
> You can override the class method :new (this is a good place to use  
> super), but be sure to return the newly minted object. Often you can  
> just override the :initialize instance method, however.

If there’s no :new class method in your class definition, then you’re  
getting Object.new (or some other super class’s :new).

---

<div class="post-metadata">

**Author:** ![mschwab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mschwab](https://www.ruby-forum.com/u/mschwab)\
**Post date:** [June 12, 2007, 7:55pm UTC](https://www.ruby-forum.com/t/question-about-initialize/106644/3 "2007-06-12T19:55:30Z")

</div>

Mike S. wrote:

> Why is the constructor method named initialize? Why not name it new  
> to be consistent?

I had this same question when I first started out. The answer I came  
to realize is that “new” is a class method that allocates the object,  
and “initialize” is the instance method that does the per-object setup  
you want.

For more details on how I came to realize this, read the “new versus  
initialize” section of this post:  
Short URL: [http://rubyurl.com/n1Q](http://rubyurl.com/n1Q)  
Full URL:  
[http://groups.google.com/group/comp.lang.ruby/tree/browse\_frm/thread/c3b22bf2d53bd68b/72313022abed07f9?rnum=1&q=matz+is+smart&\_done=%2Fgroup%2Fcomp.lang.ruby%2Fbrowse\_frm%2Fthread%2Fc3b22bf2d53bd68b%2F1b4160db0a57e90f%3Flnk%3Dgst%26q%3Dmatz%2Bis%2Bsmart%26rnum%3D1%26#doc\_72313022abed07f9](http://groups.google.com/group/comp.lang.ruby/tree/browse_frm/thread/c3b22bf2d53bd68b/72313022abed07f9?rnum=1&q=matz+is+smart&_done=%2Fgroup%2Fcomp.lang.ruby%2Fbrowse_frm%2Fthread%2Fc3b22bf2d53bd68b%2F1b4160db0a57e90f%3Flnk%3Dgst%26q%3Dmatz%2Bis%2Bsmart%26rnum%3D1%26#doc_72313022abed07f9)

---

<div class="post-metadata">

**Author:** ![mschwab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mschwab](https://www.ruby-forum.com/u/mschwab)\
**Post date:** [June 12, 2007, 11:17pm UTC](https://www.ruby-forum.com/t/question-about-initialize/106644/4 "2007-06-12T23:17:36Z")

</div>

Thanks! That link makes it much clearer.

Mike S.

---

<div class="post-metadata">

**Author:** ![mschwab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mschwab](https://www.ruby-forum.com/u/mschwab)\
**Post date:** [November 21, 2008, 12:50am UTC](https://www.ruby-forum.com/t/question-about-initialize/106644/5 "2008-11-21T00:50:09Z")

</div>

> > Why is the constructor method named initialize? Why not name it new  
> > to be  
> > consistent?  
> > Typically, :new is a class method, which calls the instantiated  
> > object’s :initialize instance method, if one is available, with the  
> > parameters passed to :new.  
> > You can override the class method :new (this is a good place to use  
> > super), but be sure to return the newly minted object. Often you can  
> > just override the :initialize instance method, however.
> 
> If there’s no :new class method in your class definition, then you’re  
> getting Object.new (or some other super class’s :new).

Would it be better to have initialize called ‘on\_new’ so that the  
connection is more firm?  
Thoughts?  
-=R

---

<div class="post-metadata">

**Author:** ![mschwab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mschwab](https://www.ruby-forum.com/u/mschwab)\
**Post date:** [November 21, 2008, 10:01pm UTC](https://www.ruby-forum.com/t/question-about-initialize/106644/6 "2008-11-21T22:01:23Z")

</div>

On 20 Nov 2008, at 23:46, Roger P. wrote:

> > If there’s no :new class method in your class definition, then you’re  
> > getting Object.new (or some other super class’s :new).
> 
> Would it be better to have initialize called ‘on\_new’ so that the  
> connection is more firm?  
> Thoughts?

Unfortunately :on\_new assumes that :initialize is only ever called  
from :new, which isn’t always the case.

Ellie

## Eleanor McHugh Games With Brains [http://slides.games-with-brains.net](http://slides.games-with-brains.net)

raise ArgumentError unless @reality.responds\_to? :reason
