That wouldn't work (you'll get an exception). You need to define "new" instead:
class RubyClass < ClrClass
def self.new (param1)
super
end
end
CLR and Ruby use different allocation schema. CLR creates objects atomically
while Ruby creates an empty/uninitialized object and then calls initialize. You
can't use Ruby's way on CLR objects that don't allow empty object allocation
(don't have default constructors).
Tomas
From: [email protected]
[mailto:[email protected]] On Behalf Of Orion Edwards
Sent: Monday, May 11, 2009 10:43 PM
To: [email protected]
Subject: Re: [Ironruby-core] Code Review: New
On 12/05/2009, at 1:49 PM, Tomas Matousek wrote:
Several cases need to be distinguished in Class#new:
1) The class defines or inherits an initializer ("initialize" method) that
is not the default Object#initializer.
a. The initializer is a Ruby method (written in Ruby).
=> Use a default constructor to create the instance and invoke the initializer
on it. If the class derives from CLR class with no default constructor an
exception is thrown.
I may be missing other context, but what happens if I want to do this:
public class ClrClass
{
public ClrClass(string param1) { ... }
// no other constructors
}
class RubyClass < ClrClass
def initialize(param1)
super(param1) # or just super should also pass the param1 if my memory is
correct...
end
end
?????
_______________________________________________
Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core