Skip to content

Instantly share code, notes, and snippets.

@dhrrgn
Created April 12, 2011 00:35
Show Gist options
  • Save dhrrgn/914687 to your computer and use it in GitHub Desktop.
Save dhrrgn/914687 to your computer and use it in GitHub Desktop.
Just a simple method to turn a slug into a human readable title
class String
def to_human_title
self.gsub(/[-_]/, " ").split(' ').map {|w| w.capitalize }.join(' ')
end
end
@zackkitzmiller
Copy link

Rails is lame

@dhrrgn
Copy link
Author

dhrrgn commented Apr 12, 2011

This particular method is not Rails specific......

@RobertAudi
Copy link

Dan, look at my fork, the use of gsub is not necessary. Good patch though :)

@dhrrgn
Copy link
Author

dhrrgn commented Apr 14, 2011

@azizLIGHT In my case it was, because I actually wanted to use this on more than just Slugs (which is why I put it right in String). So I wanted it too support strings with spaces in them already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment