Sha256: e9715938d012cc9a30402661a32a820f7aa375c5b1475174b81b171969a6a087

Contents?: true

Size: 786 Bytes

Versions: 7

Compression:

Stored size: 786 Bytes

Contents

class String

  # Converts a string to camelcase.
  #
  # By default camelcase convert to UpperCamelCase, If an argument
  # is set to +false+, then camelcase will produce lowerCamelCase.
  #
  # +camelcase+ also converts '/' to '::' which is useful for converting
  # paths to namespaces.
  #
  # Examples
  #   "camel_case".camelcase                    #=> "CamelCase"
  #   "camel/case".camelcase                    #=> "Camel::Case"
  #   "camel_case".camelcase(false)             #=> "camelCase"
  #
  def camelcase(upcase_first_letter=true)
    up = upcase_first_letter
    str = dup
    str.gsub!(/\/(.?)/){ "::#{$1.upcase}" }  # NOT SO SURE ABOUT THIS -T
    str.gsub!(/(?:_+|-+)([a-z])/){ $1.upcase }
    str.gsub!(/(\A|\s)([a-z])/){ $1 + $2.upcase } if up
    str
  end

end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
facets-2.4.0 lib/facets/string/camelcase.rb
facets-2.4.1 lib/facets/string/camelcase.rb
facets-2.4.3 lib/core/facets/string/camelcase.rb
facets-2.4.2 lib/core/facets/string/camelcase.rb
facets-2.4.4 lib/core/facets/string/camelcase.rb
facets-2.4.5 lib/core/facets/string/camelcase.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/string/camelcase.rb