Stefan Dobrev
2008-Sep-07 19:11 UTC
[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/43f9a2b3/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: init_issues.rb Type: application/octet-stream Size: 406 bytes Desc: not available URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20080907/43f9a2b3/attachment.obj>
Curt Hagenlocher
2008-Sep-07 20:18 UTC
[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: 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>
Tomas Matousek
2008-Sep-08 06:18 UTC
[Ironruby-core] Deriving from framework class with Initialize method
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: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Curt Hagenlocher Sent: Sunday, September 07, 2008 1:19 PM To: ironruby-core at rubyforge.org 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: 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/7b1fdfad/attachment-0001.html>