Ticket #787 (new defect)
MacRuby Initializers only claim a single arity
| Reported by: | ernest.prabhakar@… | Owned by: | lsansonetti@… |
|---|---|---|---|
| Priority: | major | Milestone: | MacRuby Later |
| Component: | MacRuby | Keywords: | |
| Cc: |
Description
When I write an initalizer, I only register it for a single arity:
rb_objc_define_method(cQueue, "initialize", rb_queue_init, 1);
Queue.new("foo")
Unfortunately, Objective-C will apparently fall back to the default (no-arg) initializer of the superclass, leading to an uninitalized object being allocated if I mistakenly call:
Queue.new # no args
To work around this, I've manually added an exception-throwing initializer:
static VALUE rb_raise_init(VALUE self, SEL sel) {
rb_raise(rb_eArgError, "initializer called without any arguments");
return self;
}
rb_objc_define_method(cQueue, "initialize", rb_raise_init, 0);
Would be nice if MacRuby did this automatically, to preserve Ruby-esque semantics.
Change History
Note: See
TracTickets for help on using
tickets.

