# Deriving from framework class with Initialize method

**URL:** <https://www.ruby-forum.com/t/deriving-from-framework-class-with-initialize-method/147970>\
**Category:** IronRuby\
**Created:** [September 7, 2008, 9:13pm UTC](https://www.ruby-forum.com/t/deriving-from-framework-class-with-initialize-method/147970 "2008-09-07T21:13:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefan8107](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@stefan8107](https://www.ruby-forum.com/u/stefan8107)\
**Post date:** [September 7, 2008, 9:13pm UTC](https://www.ruby-forum.com/t/deriving-from-framework-class-with-initialize-method/147970/1 "2008-09-07T21:13:31Z")

</div>

Hi guys,

I was trying to run the following code:

\*class MyObj \< DependencyObject  
end

obj = MyObj.new\*

Where DepenencyObject comes from the WPF stack (WindowsBase.dll).  
However  
this fails on the _MyObj.new_ line with strange error that wrong  
arguments  
or types are passed to initialize method. After some digging I found  
that  
DependencyObject have a private method Initialize which makes the  
problem.  
Rewriting the code like this makes it work:

_class MyObj \< DependencyObject  
def initialize  
end  
end_

May be method resolution somehow get messed up.  
Sample file attached.

Regards,  
Stefan

---

<div class="post-metadata">

**Author:** ![stefan8107](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@stefan8107](https://www.ruby-forum.com/u/stefan8107)\
**Post date:** [September 7, 2008, 10:29pm UTC](https://www.ruby-forum.com/t/deriving-from-framework-class-with-initialize-method/147970/2 "2008-09-07T22:29:47Z")

</div>

Interesting. What do you think should happen when a CLS type has a  
method whose name collides with a “special” Ruby method name like  
“initialize” or “allocate”? This isn’t an issue in IronPython because  
of Guido’s foresight in decorating all special names with double  
underscores. 🙂 Maybe for IronRuby, we could decorate certain  
CLS-imported names with a trailing underscore to avoid this kind of  
problem.

Out of curiosity, what does JRuby do in this case?

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Stefan D.  
Sent: Sunday, September 07, 2008 12:11 PM  
To: removed\_email\_address@domain.invalid  
Subject: [Ironruby-core] Deriving from framework class with Initialize  
method

Hi guys,

I was trying to run the following code:

class MyObj \< DependencyObject  
end

obj = MyObj.new

Where DepenencyObject comes from the WPF stack (WindowsBase.dll).  
However this fails on the MyObj.new line with strange error that wrong  
arguments or types are passed to initialize method. After some digging I  
found that DependencyObject have a private method Initialize which makes  
the problem. Rewriting the code like this makes it work:

class MyObj \< DependencyObject  
def initialize  
end  
end

May be method resolution somehow get messed up.  
Sample file attached.

Regards,  
Stefan

---

<div class="post-metadata">

**Author:** ![stefan8107](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@stefan8107](https://www.ruby-forum.com/u/stefan8107)\
**Post date:** [September 8, 2008, 8:22am UTC](https://www.ruby-forum.com/t/deriving-from-framework-class-with-initialize-method/147970/3 "2008-09-08T08:22:51Z")

</div>

Or maybe we could just not mangle Initialize CLR method name. That would  
prevent the conflict in most cases (.NET guidelines recommend to use  
Pascal case method names).

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Curt  
Hagenlocher  
Sent: Sunday, September 07, 2008 1:19 PM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Deriving from framework class with  
Initialize method

Interesting. What do you think should happen when a CLS type has a  
method whose name collides with a “special” Ruby method name like  
“initialize” or “allocate”? This isn’t an issue in IronPython because  
of Guido’s foresight in decorating all special names with double  
underscores. 🙂 Maybe for IronRuby, we could decorate certain  
CLS-imported names with a trailing underscore to avoid this kind of  
problem.

Out of curiosity, what does JRuby do in this case?

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Stefan D.  
Sent: Sunday, September 07, 2008 12:11 PM  
To: removed\_email\_address@domain.invalid  
Subject: [Ironruby-core] Deriving from framework class with Initialize  
method

Hi guys,

I was trying to run the following code:

class MyObj \< DependencyObject  
end

obj = MyObj.new

Where DepenencyObject comes from the WPF stack (WindowsBase.dll).  
However this fails on the MyObj.new line with strange error that wrong  
arguments or types are passed to initialize method. After some digging I  
found that DependencyObject have a private method Initialize which makes  
the problem. Rewriting the code like this makes it work:

class MyObj \< DependencyObject  
def initialize  
end  
end

May be method resolution somehow get messed up.  
Sample file attached.

Regards,  
Stefan
