You’re reading Hivelogic, a website about discovering quality, living more efficiently, and leading a simpler, more mindful life. This site was established in 2000 by Dan Benjamin, a writer, software developer, broadcaster, and usability geek (read more).


Title Case for Ruby

There’s been a great response to my request to convert Title Case, Gruber’s nifty perl-based title-casing tool into Ruby so the rest of the world (just kidding, Perl people!) can make use of it.

Here are the initial responders:

If you, too, have a version, please post it to the comments.

I haven’t had a chance to check each of them out yet, but from first blush, it appears that we have some very elegant solutions here.


Jordan Sherer

21 May 2008 at 4:16 pm

The rest of the world is split 60-40 python vs ruby, or ruby vs python. (You can pick)

You can check out my interesting Python version of his script here:
http://widefido.com/static/wf/files/title_case.py.txt

Best,
Jordan

coyote

21 May 2008 at 5:06 pm

...don’t forget those of us who prefer Java & JSP.

Tim Case

21 May 2008 at 6:25 pm

I liked the Justin French version the best…

Michael Boutros

21 May 2008 at 6:41 pm

I tossed up a page just to explain how I went at it: http://www.michaelboutros.com/index.php/projects/titlecase

Dave Phillips

21 May 2008 at 9:02 pm

Short and sweet
http://pastie.caboo.se/201355

Dylan

22 May 2008 at 1:37 am

I remember reading a book in art school written by a respected designer from Xerox (I think it was Xerox, I might be incorrect). It was almost a style guide for their company, but presented in more of a “best practices” fashion for the wider design world. Anyway, one thing I learned from this was not to set titles in “camel case”.  It’s only necessary to capitalise the first word.

Stephen

22 May 2008 at 2:31 am

It can depend on context, Dylan and is often a matter of style, like using a spaced en dash vs an em dash. Most newspapers and magazines stick to lower case, such as the Economist and Monocle. I tend to lean towards this approach, capitalising only the first word and proper nouns. A title is often itself a proper noun, however. If you were referring to an article in your body content, you would always use title case. It’s a point where typographers and designers can use their judgement, and earn their wage. ;)

John Zeratsky

22 May 2008 at 6:28 am

Stephen and Dylan:

I think it’s less important than the distinction between em and en dashes. With dashes, there are clear rules about which should be used where.

The decision to use “title case” or “sentence case” is truly one of preference, and I do not believe there are any agreed-upon rules for use. For example, the Associated Press uses sentence case, while the New York Times uses title case. Both organizations specify the capitalization scheme in their style manuals, but neither one is “right.”

aviet

22 May 2008 at 6:58 am

nobody prefers java…

Dan Benjamin

22 May 2008 at 8:52 am

When it comes to things like title case, I tend to follow the rules as set forth by The Elements of Style by Strunk & White ($9.95 at Amazon). Their recommendation is to use title case for headings.

Martin DeMello

22 May 2008 at 10:05 am

Some older code I wrote, based on Harbrace:

http://zem.novylen.net/ruby/titlecase.rb

Grant Hollingworth

22 May 2008 at 12:20 pm

http://rubyforge.org/projects/titleize

It’s available as a gem (gem install titleize) and is Rails-aware.