How to alias new() in the new allocation framework

Hi all,

What is the proper way to alias "new" in a C extension using the new
allocation framework? In other words, I want Foo.open to be an alias
to Foo.new.

// A basic Foo class

static VALUE foo_allocate(VALUE klass){ ... }
VALUE foo_init(int argc, VALUE *argv, VALUE self){ ... }

void Init_foo(){
   ...
   rb_define_alloc_func(cFoo,foo_allocate);
   rb_define_method(cFoo,"initialize",foo_init,-1);
}

Since there is no "new" method, how do create a class method that's an
alias to allocate() + initialize()? Or do I have to write it out
manually myself?

Regards,

Dan

Hi,

···

In message "Re: How to alias new() in the new allocation framework" on Sun, 17 Oct 2004 09:44:25 +0900, djberg96@hotmail.com (Daniel Berger) writes:

Since there is no "new" method, how do create a class method that's an
alias to allocate() + initialize()? Or do I have to write it out
manually myself?

Use rb_class_new_instance() in object.c.

              matz.