Skip to content

Instantly share code, notes, and snippets.

@lissdy
Created June 19, 2017 05:12
Show Gist options
  • Save lissdy/2e9472f91eb4a2c761c272aa324c3796 to your computer and use it in GitHub Desktop.
Save lissdy/2e9472f91eb4a2c761c272aa324c3796 to your computer and use it in GitHub Desktop.
Snake to Camel in Ruby
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