From: Luigi Ballabio Date: 2001-07-26T19:00:53+09:00 Subject: [ruby-talk:18564] Re: overloading [] in SWIG.i file At 07:19 AM 7/26/01 +0900, Craig Files wrote: >Hi, > > Another SWIG question: I would like to overload the [] operator in my >SWIG.i file You'll have to use Python conventions for special method names. They will be mapped to the right Ruby methods, namely: Python: Ruby: __getitem__ [] __setitem__ []= __len__ length __str__ to_s __cmp__ <=> __add__ + __sub__ - __mul__ * __div__ / __call__ call There might be others which I don't remember, though. I'm including your updated example below. Bye, Luigi %module StringVector %{ #include #include "StringVector.h" %} class StringVector { public : StringVector(); ~StringVector(); void push_back(char *); char *back(); char *front(); int size(); }; %addmethods StringVector { char *__getitem__(int index) { return (*self)[index]; } void __setitem__(int index, char *value) { (*self)[index] = value; } }