Entries Tagged as 'autotest'

Daring Fireball’s TitleCase Ruby Conversion

Update: Welcome fellow Daring Fireball readers. If you wish to get right to the actual code, feel free to skip to it.

I recently took up the challenge from John Gruber and Dan Benjamin to port John’s TitleCase.pl Perl script to an equivalent Ruby version. It seemed to me that converting someone’s script to another language would be a fun experiment to help learn any language. I was right.

I set up a git repository at GitHub.

I decided to write an extension to the String class in Ruby, as that would allow you to use this String#titlecase method anywhere and you could therefore write a standard input processing script trivially with this library included via a gem. Writing the extension also gave me a great excuse to learn more about RSpec, a nice Ruby testing library. I wrote the tests in RSpec, but I admit my tests were a quick hack to get them working at 3 in the morning, not good spec tests. Maybe someday I will convert them into real sentences of intent, as they should be. Either way, it was fun to try out Test Driven Development, and using the autotest function of the ZenTest gem to watch the tests start to pass as the script came along.

So after a few hours of learning about RSpec, ZenTest, all the tests from Gruber pass, even the one he lists as not working with his script. I took a different approach in how to process the titles, so there are not as many gotchas to fix up after processing either.

If you find it useful, let me know. And of course, fork the repo and send back some more test examples and any bugs you find.

P.S. Daniel also converted my Ruby version to PHP. We are going to use it at BitLeap for various things. He had also said about seeing about making a WordPress plugin out of it. So, I will prod Daniel to see if he will setup a public repository for it.