[Ironruby-core] Deriving from framework class with Initialize method

Curt Hagenlocher curth at microsoft.com
Sun Sep 7 16:18:39 EDT 2008


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: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Stefan Dobrev
Sent: Sunday, September 07, 2008 12:11 PM
To: ironruby-core at rubyforge.org
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20080907/69237805/attachment.html>


More information about the Ironruby-core mailing list