Init_xxx(with arg ?) in C for ruby ext?

hey all,

new to C, i’m writing a ruby ext, i wonder if we could pass an arg to
Init_xxx(type * arg) ???

this is to have a constructor in ruby like that :

trick=MyClass.new(“my arg”)

and if not does exists a workaround ???

On Aug 8, 2006, at 9:45 AM, Une bévue wrote:

hey all,

new to C, i’m writing a ruby ext, i wonder if we could pass an arg to
Init_xxx(type * arg) ???

this is to have a constructor in ruby like that :

trick=MyClass.new(“my arg”)

and if not does exists a workaround ???

The Init_ method initializes the shared library, it is not the
constructor.

Write your #initialize to take arguments and MyClass.new “my arg”
will work.


Eric H. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

Une bévue [email protected] wrote:

ew to C, i’m writing a ruby ext, i wonder if we could pass an arg to
Init_xxx(type * arg) ???

this is to have a constructor in ruby like that :

trick=MyClass.new(“my arg”)

and if not does exists a workaround ???

it is :

rb_define_singleton_method(rb_cMyClass, "new", cd_new, 1);

On Aug 8, 2006, at 10:25 AM, Une bévue wrote:

it is :

rb_define_singleton_method(rb_cMyClass, "new", cd_new, 1);

No. MyClass.new is inherited from Class.

rb_define_method(rb_cMyClass, “new”, cd_initialize, 1);

It works “just like” regular ruby.


Eric H. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

On Aug 8, 2006, at 12:13 PM, Eric H. wrote:

and if not does exists a workaround ???

it is :

rb_define_singleton_method(rb_cMyClass, "new", cd_new, 1);

No. MyClass.new is inherited from Class.

rb_define_method(rb_cMyClass, “new”, cd_initialize, 1);

Oops.

rb_define_method(rb_cMyClass, “initialize”, cd_initialize, 1);


Eric H. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs