The original SMBC specifies that everything except the nouns should be nurbled; your implementations replace the nouns themselves.
I'd like to refactor the Ruby example, but I'd like to know what the proper implementation should be!
I'd like to refactor the Ruby example, but I'd like to know what the proper implementation should be!
The Ruby example was already correct.
(words - @@nouns).each do |w|
text.gsub!(/(\b)#{w}(\b)/i, '\1<span class="nurble">nurble</span>\2')
end
EDIT: oops, backslash. Also, in the example, line 19, where you have 'sub', don't you mean 'pattern'?And thanks for the typo catch, too.
And, just FYI you do need to escape the backrefs or use single quotes, like:
"\\1<span class=\"nurble\">nurble</span>\\2"