20 Comments
It’s been a while since the last edition of Rubyize this. I have waited all this time because I like when people become impatient. I have received 254 939 emails from desperate people asking me : “When will you post your 5th edition?”, “Is it hard to be that excellent?”, “You rock Frank. Warm kisses… - Vanessa” and such.
Hold on a second, gotta update my checklist :
2 days ago I received an email from Scott Patten, an active web developer based in Vancouver. He is currently helping to organize RubyCamp Vancouver 2008, which is a free one-day gathering for Rubyists and Railers. In his email, he asked me if he could use the Rubyize this concept for an (un)conference event that would be held at RubyCamp. Of course, I said yes! It now seems official : Rubyize this will be part of RubyCamp Vancouver 2008! I was also happy when I read the following : “the audience will submit their refactorings to Refactor My Code“. That’s good for you, Marc!
Important : The future of Rubyize this
I need your help to create ugly pieces of code! I don’t want to become repetitive from edition to edition so I’d really appreciate if you could send me some fresh ideas. Just send me an email to frank@rubyfleebie.com containing an ugly piece of code as well as a small intro to help us understand what this is all about. I’ll make sure to put your name as well as a link to your website (if any) in the appropriate Rubyize This edition.
Enough babbling :
Tom wrote a very simple ruby script to highlight some words in a text. He chose to highlight the words with asterisks, like *that* (In 2 months, perhaps Tom will have to use his script to produce HTML output or something else… he will be screwed with those basic asterisks). Tom has absolutely no ruby background, help him refactor his code ala Ruby, that is : short, clean and simple.
By the way, Tom didn’t put a lot of effort in his algorithm. His dumb gsub thing will mistakenly replace parts of words instead of whole words only. Maybe some improvements would be needed there.
20 Commentswow! that’s awesome! glad to see your concept getting more and more traction and thx for promoting RmC w/ it, you’re the best.
Can’t wait for the t-shirt “Rubyize-me Frank”, when is it shipping already?
Rubyize this : 5th edition…
Revision 2, this time passing in list of words to highlight as a function argument like macournoyer did (first reply), which is much better than accessing a named variable outside of the function….
Rubyize this : 5th edition…
Good solutions above. This is overkill, but can’t think of anything else that hasn’t already been done….
Congrats for the RubyCamp Vancouver Frank! It’s nice to see that your work is appreciated over the whole country…
Rubyize this : 5th edition…
i purposely wrote this without looking at the refactorings… funny how close it still is but it’s a bit different. a little more verbose imo but extensible. the only issue i have with it is that you are limited to one a single delimiter….
Rubyize this : 5th edition…
I’m sure the String#pad (not sure about the name either) utility function added here is available somewhere, but anyways. Also using the block version of gsub this time….
Wow, thanks all for your contributions… some pretty good stuff here! It’s always fun and instructive to watch how people solve problems in ruby.
@Marc,
Thanks! About the rubyize-this shirts, I’m starting to think about it seriously ![]()
Rubyize this : 5th edition…
Nothing major here, just made it case insensitive. An issue I have is that hyphenated words like “monkey-wrench” will still get highlighted and I have no idea how to get the regexp to ignore words beginning or ending with a -….
Rubyize this : 5th edition…
another one, neither of these work on contractions, this one features recursion and only involves modifying string.
This one outputs:
*hello* world, what’s *up*?
…
Rubyize this : 5th edition…
found a bug in that one, didnt work when you had a full sentence and passed in a mark.
This one will correctly output +hello+ world, what’s +up+?
I’m going to stop now, sorry for the triple post….
@Mike, I like the fact that you used recursion. It’s an interesting and clever approach. No worry about the triple post ![]()
Rubyize this : 5th edition…
Regexp.union is your friend! This also demonstrates a typical use of the splat operator to turn an array into an argument list, and the usage of back-references in global substitutions. One thing that I found recently is that your replacement string …

