Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/KCommercialPipeline/core/resource/swift/swift_generator.rb,
lib/KCommercialPipeline/core/resource/code_generator/code_generator.rb

Instance Method Summary collapse

Instance Method Details

#camelize(uppercase_first_letter = true) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/KCommercialPipeline/core/resource/swift/swift_generator.rb', line 3

def camelize(uppercase_first_letter = true)
  string = self
  if uppercase_first_letter
    string = string.sub(/^[a-z\d]*/) { |match| match.capitalize }
  else
    string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { |match| match.downcase }
  end
  string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub("/", "::")
end