From: "Aleksi Niemelä" Date: 2000-12-13T04:28:41+09:00 Subject: [ruby-talk:7098] RE: Rubyize this method Morris Chris asked: > I'd hoped there was a built in > string method to do what this does I'm not sure there's a method for this. I guess there's not. But it's not too hard to do by yourself, and even easy enough to write inline when needed. But here's an example of wrapped version. I'd use the name you've chosen (if it's good), and use regexps: class String def lopOff(substr) # actually pattern might be better name sub!(substr, "") # and sub!(/^#{substr}/, "") better end # implementation end a = "test this" p a #=> "test this" a.lopOff("tes") p a #=> "t this" Regexps might be slower than needed, in this kind of easy case, and handwritten C version, along the lines of your Ruby version could fit the place. Nevertheless, I think this is not so common case that we should add it to standard String. > I assume it's probably staring me in the face... It might be. There might be some magic with indices, but usually when I think of strings and manipulations I start to wonder the shape of regexp... - Aleksi