String#gsub! Snippet
Tuesday, October 20th, 2009 · 0 comments
Here's a little snippet in Ruby that turns this:
Boy: Hello world!
Girl: Welcome!
Boy: How are you?
Girl: Good!
In to this:
<b>Boy</b>: Hello world!
<b>Girl:</b> Welcome!
<b>Boy:</b> How are you?
<b>Girl:</b> Good!
And here it is:
string.gsub!(/\w+:/) { |match| match = content_tag(:b, match) }
Great for oh, maybe IRC quotes on a tumblelog? ;)
