Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
to_underscore implementation
class String
# ruby mutation methods have the expectation to return self if a mutation occurred, nil otherwise. (see
def to_underscore!
g = gsub!(/(.)([A-Z])/,'\1_\2'); d = downcase!
g || d
def to_underscore
dup.tap { |s| s.to_underscore! }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment