Created
December 21, 2014 22:08
-
-
Save josephbridgwaterrowe/3fca3f52c73d75c0bf41 to your computer and use it in GitHub Desktop.
String refinements
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
module StringExtensions | |
refine String do | |
# "Brute force" underscore the string. | |
# Removes any non-alpha characters for clean symbol ready strings. | |
def brute_underscore | |
self.gsub(/::/, '/'). | |
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). | |
gsub(/([a-z\d])([A-Z])/,'\1_\2'). | |
gsub(/([\\][\"])/,''). | |
tr('-', '_'). | |
tr(' ', '_'). | |
squeeze('_'). | |
downcase | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm sure that this doesn't really do everything it claims to yet, but I will add the functionality once I identify its failings... I also need to add some tests and perhaps put this into a Gem/repo.