Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
How to define multiple initialize methods in embedded mode?
chirag80bece
3/10/2008 8:21:00 AM
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.
--
Posted via
http://www.ruby-...
.
1 Answer
Rick DeNatale
3/10/2008 11:31:00 AM
0
On 3/10/08, Chirag Mistry <chirag80bece@gmail.com> wrote:
> 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.
--
Rick DeNatale
My blog on Ruby
http://talklikeaduck.denh...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
How to define multiple initialize methods in embedded mode?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password