How to alias new() in the new allocation framework

D

Daniel Berger

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
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: How to alias new() in the new allocation framework"
on Sun, 17 Oct 2004 09:44:25 +0900, (e-mail address removed) (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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,591
Members
45,103
Latest member
VinaykumarnNevatia
Top