Skip to content

Instantly share code, notes, and snippets.

@noahgibbs
Created April 28, 2019 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noahgibbs/6a5ce80b22c11c463ca9709eed88d9ef to your computer and use it in GitHub Desktop.
Save noahgibbs/6a5ce80b22c11c463ca9709eed88d9ef to your computer and use it in GitHub Desktop.
R00lz.to_underscore, for those who hate typing out regexps visually.
# 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