From: Geert Fannes Date: 2006-01-30T18:12:13+09:00 Subject: inheritance from C object with different parameter count ------_=_NextPart_001_01C6257C.D03CA54C Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello, I'm trying to create a derived class (ruby class) from a C-implemented class. Everything works fine, until I tried to add a parameter to the derived class. When I derive from a pure ruby base class, everything works as should be, extra parameter or not. Does someone know what is going on or what I am doing wrong? =20 I am getting the following output: =20 gfannes@lt-gfannes help $ ruby test.rb test.rb:21:in `new': wrong number of arguments (1 for 0) (ArgumentError) from test.rb:21 =20 =20 This is the ruby file containing the derivation from the base class. If bCLib is set to false, things work as should be. ##############test.rb###################### bCLib=3Dtrue =20 if bCLib require('base.so') else class Base def initialize() puts("base") end end end =20 class Derived < Base def initialize(parameter) puts("init derived") super() puts("finished super") end end =20 Derived.new('parameter') ########################################## =20 This is the C-file that implements the base class in C ######################base.c##################### #include "ruby.h" #include #include =20 typedef struct{ double dValue; } baseStruct; =20 =20 VALUE f_new0(VALUE klass) { printf("f_new0.\n"); VALUE rBase; baseStruct *pBase=3Dmalloc(sizeof(baseStruct)); rBase =3D Data_Wrap_Struct(klass, 0, free, pBase); printf("before rb_obj_call_init.\n"); rb_obj_call_init(rBase, 0, 0); printf("f_new0 finished.\n"); return rBase; } =20 VALUE f_initialize0(VALUE self) { printf("f_initialize0.\n"); return self; } =20 VALUE cBase; =20 void Init_base() { cBase=3Drb_define_class("Base",rb_cObject); rb_define_singleton_method(cBase, "new", f_new0, 0); rb_define_method (cBase, "initialize", f_initialize0, 0); } ################################################# =20 Everything is compiled using extconf.rb #############extconf.rb########################## require 'mkmf' create_makefile('base') ################################################# =20 ------_=_NextPart_001_01C6257C.D03CA54C--