Created
June 19, 2017 05:12
-
-
Save lissdy/2e9472f91eb4a2c761c272aa324c3796 to your computer and use it in GitHub Desktop.
Snake to Camel in Ruby
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
module SnakeCamel | |
def to_camel | |
self.gsub(/(?:\b|_)([a-z])/) { Regexp.last_match(1).upcase } | |
end | |
end | |
class String | |
include SnakeCamel | |
end | |
Usage: "under_armour".to_camel => "UnderArmour" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment