Projects

Ticket #787 (new defect)

Opened 19 months ago

Last modified 14 months ago

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

Changed 14 months ago by lsansonetti@…

  • milestone changed from MacRuby 0.7 to MacRuby Later
Note: See TracTickets for help on using tickets.