Sha256: 90a95b4a8ee5d9f62cc185d639049ee43a8319a9d2f234991e77d663bf42988b

Contents?: true

Size: 707 Bytes

Versions: 7

Compression:

Stored size: 707 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

7 entries across 7 versions & 1 rubygems

Version Path
facets-2.8.4 lib/core/facets/string/modulize.rb
facets-2.8.3 lib/core/facets/string/modulize.rb
facets-2.8.2 lib/core/facets/string/modulize.rb
facets-2.8.1 lib/core/facets/string/modulize.rb
facets-2.8.0 lib/core/facets/string/modulize.rb
facets-2.7.0 lib/core/facets/string/modulize.rb
facets-2.6.0 lib/core/facets/string/modulize.rb