Created
December 6, 2013 08:05
-
-
Save defp/7820179 to your computer and use it in GitHub Desktop.
驼峰转为下划线
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
| 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