[MacRuby-devel] [MacRuby] #787: MacRuby Initializers only claim a single arity

MacRuby ruby-noreply at macosforge.org
Tue Jul 13 15:57:05 PDT 2010


#787: MacRuby Initializers only claim a single arity
----------------------------------------+-----------------------------------
 Reporter:  ernest.prabhakar@…          |       Owner:  lsansonetti@…        
     Type:  defect                      |      Status:  new                  
 Priority:  major                       |   Milestone:  MacRuby 0.7          
Component:  MacRuby                     |    Keywords:                       
----------------------------------------+-----------------------------------
 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.

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/787>
MacRuby <http://macruby.org/>



More information about the MacRuby-devel mailing list