Created
April 28, 2019 15:52
-
-
Save noahgibbs/6a5ce80b22c11c463ca9709eed88d9ef to your computer and use it in GitHub Desktop.
R00lz.to_underscore, for those who hate typing out regexps visually.
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
# r00lz/lib/r00lz.rb | |
module R00lz | |
def self.to_underscore(s) | |
s.gsub( | |
/([A-Z]+)([A-Z][a-z])/, | |
'\1_\2').gsub( | |
/([a-z\d])([A-Z])/, | |
'\1_\2').downcase | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment