Skip to content

Instantly share code, notes, and snippets.

@defp
Created December 6, 2013 08:05
Show Gist options
  • Select an option

  • Save defp/7820179 to your computer and use it in GitHub Desktop.

Select an option

Save defp/7820179 to your computer and use it in GitHub Desktop.
驼峰转为下划线
class String
def snake_case
return downcase if match(/\A[A-Z]+\z/)
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
gsub(/([a-z])([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