From: ts Date: 2001-06-22T00:08:48+09:00 Subject: [ruby-talk:16710] Re: how to call super from singleton method? >>>>> "A" == Andi Riedl writes: A> On Thu, 21 Jun 2001 21:04:17 +0900, ts wrote: >> rb_alias(CLASS_OF(x), rb_intern("inspect_old"), rb_intern("inspect")); ^^^^^^^^^^^ ^^^^^^^^^^^ >> rb_define_singleton_method(x, "inspect", myInspect, 0); ^ ^ A> unfortunately this solution breaks encapsulation, too: A> cluttering rb_cHash's globally visible namespace for A> the sake of defining just one singleton method. rb_cHash was not modified pigeon% cat tt.c #include #include VALUE myInspect (VALUE self) { return rb_str_concat(rb_str_new2("myInspect : "), rb_funcall(self, rb_intern("inspect_old"), 0)); } int main() { VALUE x, y, z; ruby_init(); x = rb_hash_new(); z = rb_hash_new(); rb_alias(CLASS_OF(x), rb_intern("inspect_old"), rb_intern("inspect")); rb_define_singleton_method(x, "inspect", myInspect,0); /* call now: */ y = rb_funcall(x,rb_intern("inspect"),0); printf ("x <%s>\n",STR2CSTR(y)); y = rb_funcall(z,rb_intern("inspect"),0); printf ("z <%s>\n",STR2CSTR(y)); return 0; } pigeon% pigeon% tt x z <{}> pigeon% Guy Decoux