From: Victor Reyes Date: 2008-06-08T22:04:01+09:00 Subject: Re: Remove Parts of a String ------=_Part_10856_23883471.1212930317116 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Sat, Jun 7, 2008 at 12:04 PM, Dave Bass wrote: > Victor Reyes wrote: > > to understand: > > > > str.gsub(/:[^,]*(?:$|(?=,))/,'').split( ',') > > > > you need a PhD in "General Expresionology". Ruby is supposed to be > > simple. > > At a glance you can see that gsub does something to str, and then split > does something to the result. So the top level's quite straightforward. > > The gsub regexp is not easy to understand however, and this is one of > the problems with regexps in general. They're concise but obscure. > Generally speaking one builds them up a little at a time, using quite a > bit of trial and error -- or at least, that's how I do it, maybe other > people get there in one! > > A regexp like this deserves several lines of comments to explain what's > going on. For some reason coders hate writing comments. > > I would tend to do a job like this in several stages rather than in one > line. I've learnt by bitter experience that my future self finds it > difficult to understand concise code that my past self has written! > -- > Posted via http://www.ruby-forum.com/. > > Well, this is what I tried to say earlier. This kind of solution although beautiful and concise, it is difficult to understand unless you do it often or document it very well. Perhaps its elegance had to do with its complexity or something like that! Victor ------=_Part_10856_23883471.1212930317116--