Sha256: 402752ee494c83ffdf432014ac0f3c3676d4d242980fc4b6a8bf567c7a3324d5

Contents?: true

Size: 718 Bytes

Versions: 6

Compression:

Stored size: 718 Bytes

Contents

class String

  # Converts a string to module name representation.
  #
  # This is essentially #camelcase. It also converts
  # '/' to '::' which is useful for converting
  # paths to namespaces.
  #
  # Examples
  #
  #   "method_name".modulize    #=> "MethodName"
  #   "method/name".modulize    #=> "Method::Name"
  #
  #--
  # Rails definition ...
  #
  #    gsub(/__(.?)/){ "::#{$1.upcase}" }.
  #    gsub(/\/(.?)/){ "::#{$1.upcase}" }.
  #    gsub(/(?:_+)([a-z])/){ $1.upcase }.
  #    gsub(/(^|\s+)([a-z])/){ $1 + $2.upcase }
  #
  #++
  def modulize
    gsub('__','/').
    gsub(/\/(.?)/){ "::#{$1.upcase}" }.
    gsub(/(?:_+|-+)([a-z])/){ $1.upcase }.
    gsub(/(\A|\s)([a-z])/){ $1 + $2.upcase }
  end

end

Version data entries

6 entries across 5 versions & 1 rubygems

Version Path
facets-2.9.2 lib/core/facets/string/modulize.rb
facets-2.9.2 src/core/facets/string/modulize.rb
facets-2.9.1 lib/core/facets/string/modulize.rb
facets-2.9.0 lib/core/facets/string/modulize.rb
facets-2.9.0.pre.2 lib/core/facets/string/modulize.rb
facets-2.9.0.pre.1 lib/core/facets/string/modulize.rb