From: David Alan Black Date: 2001-09-21T05:25:29+09:00 Subject: [ruby-talk:21461] Re: chain methods inside and outside the class; how to intermingle mine and Strings' methods? Hello -- On Fri, 21 Sep 2001, Kevin Smith wrote: > --- "Frykholm, Niklas" wrote: > > self.class.new(self.gsub /\d/,'') > (snip) > > Your class, HoX should be as polite, that is why > > delete_digits should use self.class.new rather than > > HoX.new, it makes it possible for someone to create a > > subclass of HoX and chain the method calls. > > Nice bit about new--I hadn't thought of that. But wouldn't > this be the same (and slightly simpler)? > > self.class.new(gsub /\d/,'') > > Or perhaps (I don't have Ruby in front of me) this: > > class.new(gsub /\d/,'') The bare "class" usually doesn't parse because Ruby thinks it's going to be a class definition. You can always use the synonym "type", or just include the "self". David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav