How to define multiple initialize methods in embedded mode?

C

Chirag Mistry

Hi

I have embedded Ruby in C++ application. I want to define multiple
"initialize" method in the Ruby class. Please let me know which sequence
of call is required to implement it? I tried following sequence of call
but it is not working. It only defines last "initialize" method.

Code snapshot:
####################
// Define class under “MyModule†module
mMyClass = rb_define_class_under(mMyModule, "MyClass", rb_cObject);
rb_gc_register_address(&mMyClass);
// Define “initialize†method without any parameter
rb_define_method(mMyClass, "initialize",
reinterpret_cast<VALUE(*)(...)>(defaultInitialize), 0);
// Define “initialize†method with one parameter
rb_define_method(mMyClass, "initialize",
reinterpret_cast<VALUE(*)(...)>(initialize1), 1);
####################

In above code, it is only calling “initialize1†which accepts single
parameter. Please let me know what is wrong in above code snapshot and
correct it so I can define more than one “initialize†method in same
class.
 
R

Rick DeNatale

Hi

I have embedded Ruby in C++ application. I want to define multiple
"initialize" method in the Ruby class. Please let me know which sequence
of call is required to implement it? I tried following sequence of call
but it is not working. It only defines last "initialize" method.

Code snapshot:
####################
// Define class under "MyModule" module
mMyClass = rb_define_class_under(mMyModule, "MyClass", rb_cObject);
rb_gc_register_address(&mMyClass);
// Define "initialize" method without any parameter
rb_define_method(mMyClass, "initialize",
reinterpret_cast<VALUE(*)(...)>(defaultInitialize), 0);
// Define "initialize" method with one parameter
rb_define_method(mMyClass, "initialize",
reinterpret_cast<VALUE(*)(...)>(initialize1), 1);
####################

In above code, it is only calling "initialize1" which accepts single
parameter. Please let me know what is wrong in above code snapshot and
correct it so I can define more than one "initialize" method in same
class.

It can't be done. Ruby doesn't have the concept of overloading.
 

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,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top