Created
September 17, 2012 21:01
-
-
Save barelyknown/3739741 to your computer and use it in GitHub Desktop.
space_case method for strings to humanize camelcase class names
This file contains 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 | |
# Change "HelloWorld" into "Hello World" while keeping "HELLOWORLD" as "HELLOWORLD" | |
# Useful as an alternative to humanize when presenting a list of class names | |
def space_case | |
split(/((?<=[a-z])[A-Z])/).inject { |whole, part| whole += (part =~ /^[A-Z]$/) ? " #{part}" : part } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment