Created
October 3, 2016 19:51
-
-
Save fornellas/73ba648e6f2c68c21b9ffbfcaa60885f to your computer and use it in GitHub Desktop.
This file contains 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
# Convert given strig in CamelCase to snake_case. | |
def camel_to_snake_case string | |
string.gsub(/([^A-Z])([A-Z])/, '\1_\2').downcase | |
end | |
# Convert given string in snake_case to CamelCase | |
def snake_to_camel_case string | |
string.split('_').map(&:downcase).map(&:capitalize).join('') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment