Created
January 19, 2009 09:40
Revisions
-
avdgaag renamed this gist
Jan 19, 2009 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
avdgaag created this gist
Jan 19, 2009 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ original = 'ThisIsAStringInCamelCaseWithNumbersLike12And14' # Convert a CamelCase string to snake_case snake_case = original.gsub(/([\w^_](?=[A-Z]))|([a-z](?=\d+))/, '\1\2_').downcase # Convert a snake_case string to CamelCase camel_case = snake_case.gsub(/^\w|_\w/) { |match| match[-1,1].upcase } puts snake_case # => "this_is_a_string_in_camel_case_with_numbers_like_12_and_14" puts camel_case # => "ThisIsAStringInCamelCaseWithNumbersLike12And14"