Live and Learn

April 19th, 2010  |  Published in ruby

Well, from yesterday’s entry on Ruby and Joomla and such:

article_alias.gsub!(/\-{2,}/,"-")

First, I guess article_alias.gsub!(/\-+/,"-") is less noisy by three characters. I don’t know how I got into the habit of using intervals instead of quantifiers, but it’s all over the place in my scripts.

Second, just this morning, Ruby Quicktips pointed out the “squeeze” method, which would work like this:

article_alias.squeeze!("-")

Tidy!

Leave a Response

© Michael Hall, licensed under a Creative Commons Attribution-ShareAlike 3.0 United States license.