Skip to content

Instantly share code, notes, and snippets.

@mrkplt
Created July 10, 2014 14:44
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 mrkplt/c6fb95cb613fed2075bc to your computer and use it in GitHub Desktop.
Save mrkplt/c6fb95cb613fed2075bc to your computer and use it in GitHub Desktop.
Turn in a string into a valid local variable name.
def variablize(string)
sanitized_string = string.chomp('=')
sanitized_string = sanitized_string.gsub(/([^a-z0-9_])/i, '_')
sanitized_string[0] = sanitized_string[0].downcase.sub(/[0-9]/, '_')
sanitized_string
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment