From: "Jürgen Mangler" Date: 2004-12-28T17:06:57+09:00 Subject: Re: Extensions, Internal myObj.text.gsub!(/a/,"b") will not alter the string returned by #text, because it returns a duplicated value from inside an extension. Sorry i can't explain it better. think of something like: VALUE rbxs_node_text_get(VALUE self) { rbxs_node *prbxs; Data_Get_Struct(self, rbxs, prbxs); return(rb_str_new2(CONVERT_FROM_SOME_STRING_FORMAT(prbxs->node->content))); } VALUE rbxs_node_text_set(VALUE self, VALUE text) { rbxs_node *prbxs; Data_Get_Struct(self, rbxs, prbxs); setSomeStrangeTextFormat(prbxs->node->content,STR2CSTR(text)); } when calling #gsub! on something that rbxs_node_text_get returns, it just don't alters the object it is called on, because it can't. Content can only be set through setSomeStrangeTextFormat Maybe i missed something important, but after discussing a bit on #ruby-lang, someone came up with "you could also create a wrapper string which has .gsub! and so on replaced with special versions that go through the setter" which seemed somehow ... uncool to me. I though that maybe I can tell a string, what to call to deliver something back (in this case rbxs_node_text_set). A callback function. (Described in the first detail) Sorry for my bad english. J�rgen Yukihiro Matsumoto wrote: > Hi, > > In message "Re: Extensions, Internal" > on Tue, 28 Dec 2004 14:54:50 +0900, J�rgen Mangler writes: > > |rb_define_method(cSimpleNode, "text", rbxs_node_text_get, 0); > |rb_define_method(cSimpleNode, "text=", rbxs_node_text_set, 1); > | > |I've to return duplicates of the string, because the string format is > |incompatible/the string can only be set by calling a function. So a > |gsub! will not work as expected. > > I'm afraid I don't understand what you want. What do you expect for a > gsub! to work? > > matz. > >