Created
April 12, 2011 00:35
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def to_human_title | |
self.gsub(/[-_]/, " ").split(' ').map {|w| w.capitalize }.join(' ') | |
end | |
end |
This particular method is not Rails specific......
Dan, look at my fork, the use of gsub
is not necessary. Good patch though :)
@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
Rails is lame