# Initialise

**URL:** <https://www.ruby-forum.com/t/initialise/193912>\
**Category:** Ruby\
**Created:** [August 26, 2010, 3:04pm UTC](https://www.ruby-forum.com/t/initialise/193912 "2010-08-26T15:04:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tensaiji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/6de8d8/32.png) [@tensaiji](https://www.ruby-forum.com/u/tensaiji)\
**Post date:** [August 26, 2010, 3:04pm UTC](https://www.ruby-forum.com/t/initialise/193912/1 "2010-08-26T15:04:49Z")

</div>

Hi all,

Being English and able to spell proper like, innit, I find I’m creating  
a lot of stupid errors by writing `def initialise` a lot. I had the  
bright idea of making an alias to stop this transatlantic turmoil, but  
I’ve no idea where to put it. Everything I’ve looked up boils down to  
“don’t worry, initialize is sort of magic behind the scenes, just call  
new…”

I tried this:

class Object  
alias :initialise :initialize  
end

but it didn’t work. Is this possible, or do I have to start writing like  
the lead singer from Radiohead sings?

Regards,  
Iain

---

<div class="post-metadata">

**Author:** ![tensaiji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/6de8d8/32.png) [@tensaiji](https://www.ruby-forum.com/u/tensaiji)\
**Post date:** [August 26, 2010, 3:50pm UTC](https://www.ruby-forum.com/t/initialise/193912/2 "2010-08-26T15:50:28Z")

</div>

Iain B.:

> Being English and able to spell proper like, innit, I find I’m  
> creating a lot of stupid errors by writing `def initialise`  
> a lot.

🙂

> I tried this:

> class Object  
> alias :initialise :initialize  
> end

> but it didn’t work.

It definitely does work â€“ you can start using #initialise instead of  
#initialize in your code. Note that it doesnâ€™t make other code (notably,  
BasicObject.new) call #initialise all of a sudden, which is probably  
what youâ€™d rather have, innit?

(You probably want to redeclare BasicObject.new,  
except you probably donâ€™t want to, not _really_.)

â€” Piotr S.

---

<div class="post-metadata">

**Author:** ![tensaiji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/6de8d8/32.png) [@tensaiji](https://www.ruby-forum.com/u/tensaiji)\
**Post date:** [August 26, 2010, 4:04pm UTC](https://www.ruby-forum.com/t/initialise/193912/3 "2010-08-26T16:04:31Z")

</div>

I see your point.

I would follow the language. Issues with other coders and such will  
arise…

Alias for Initialize doesn’t fit.

1. Initialize is a private method.
2. The Object inherently calls Initialize upon creation. When the object  
is  
instantiated its calls Initialize. Alias is created by this time, and  
there  
is no no need to call it after creation.
3. Aliasing in the way you are attempting is calling it a second time.

Its probably better to follow the language.

Just a quick irb session:

irb(main):001:0\> class Joe  
irb(main):002:1\> alias :initialise :initialize  
irb(main):003:1\> def initialize  
irb(main):004:2\> print “where you going with that gun in your hand?”  
irb(main):005:2\> @gun = 0  
irb(main):006:2\> end  
irb(main):007:1\> end  
=\> nil  
irb(main):008:0\> jimi = Joe.new  
where you going with that gun in your hand?=\> #\<Joe:0x36a22c @gun=0\>  
irb(main):009:0\> jimi.initialise  
NoMethodError: private method `initialise’ called for #\<Joe:0x36a22c  
@gun=0\>  
from (irb):9

---

<div class="post-metadata">

**Author:** ![tensaiji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/6de8d8/32.png) [@tensaiji](https://www.ruby-forum.com/u/tensaiji)\
**Post date:** [August 26, 2010, 4:34pm UTC](https://www.ruby-forum.com/t/initialise/193912/4 "2010-08-26T16:34:23Z")

</div>

On 26 Aug 2010, at 15:03, Joseph E. Savard wrote:

> I would follow the language. Issues with other coders and such will arise…

The language I was trying to follow was English, but there you go… 🙂

On 26 Aug 2010, at 14:49, Piotr S. wrote:

> Note that it doesn’t make other code (notably,  
> BasicObject.new) call #initialise all of a sudden, which is probably  
> what you’d rather have, innit?

That was the one I was going for. Ah well.

Thanks both for your input. I suppose my only recourse now is to start  
hacking on the Ruby source and get my patch submitted in time for Ruby  
2.0 🙂

Regards,  
Iain

---

<div class="post-metadata">

**Author:** ![tensaiji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/6de8d8/32.png) [@tensaiji](https://www.ruby-forum.com/u/tensaiji)\
**Post date:** [August 26, 2010, 4:54pm UTC](https://www.ruby-forum.com/t/initialise/193912/5 "2010-08-26T16:54:54Z")

</div>

class Object  
alias :old\_initialize :initialize  
def initialize(\*args,&blk)  
if respond\_to? :initialise  
initialise(\*args,&blk)  
else  
old\_initialize(\*args,&blk)  
end  
end  
end

class Foo  
def initialize(n)  
@n = n  
end  
end

class Bar  
def initialise(m)  
@m = m  
end  
end

p Foo.new(123)  
p Bar.new(456)

You get a warning about redefining initialize, but it seems to work.

> I suppose my only recourse now is to start  
> hacking on the Ruby source and get my patch submitted in time for Ruby  
> 2.0 🙂

That will be released some time between perl 6 and hell freezing over  
🙂

---

<div class="post-metadata">

**Author:** ![tensaiji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/6de8d8/32.png) [@tensaiji](https://www.ruby-forum.com/u/tensaiji)\
**Post date:** [August 26, 2010, 7:49pm UTC](https://www.ruby-forum.com/t/initialise/193912/6 "2010-08-26T19:49:57Z")

</div>

On 26 Aug 2010, at 15:54, Brian C. wrote:

> end
> 
> p Foo.new(123)  
> p Bar.new(456)
> 
> You get a warning about redefining initialize, but it seems to work.

Thanks, I’ll give that a shot.

> > I suppose my only recourse now is to start  
> > hacking on the Ruby source and get my patch submitted in time for Ruby  
> > 2.0 🙂
> 
> That will be released some time between perl 6 and hell freezing over  
> 🙂

I was thinking of using Perl6 to write Ruby2.0 🙂

Regards  
Iain

---

<div class="post-metadata">

**Author:** ![tensaiji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/6de8d8/32.png) [@tensaiji](https://www.ruby-forum.com/u/tensaiji)\
**Post date:** [August 27, 2010, 10:15am UTC](https://www.ruby-forum.com/t/initialise/193912/7 "2010-08-27T10:15:41Z")

</div>

2010/8/26 Brian C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> end
> 
> p Foo.new(123)  
> p Bar.new(456)
> 
> You get a warning about redefining initialize, but it seems to work.

What about inheritance especially in light of “super”? I’m with  
Joseph here: better adjust to the programming language and stick with  
“initialize”.

> > I suppose my only recourse now is to start  
> > hacking on the Ruby source and get my patch submitted in time for Ruby  
> > 2.0 🙂
> 
> That will be released some time between perl 6 and hell freezing over  
> 🙂

Can’t be too long though. 🙂

Cheers

robert
