Sha256: 5f604c1461d565d3547f6f48cff28d597a67cdeb408d031b173795d2aa63bbc6

Contents?: true

Size: 797 Bytes

Versions: 4

Compression:

Stored size: 797 Bytes

Contents

class String

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

  # Compare to ActiveSupport's definition:
  #
  #    gsub(/__(.?)/){ "::#{$1.upcase}" }.
  #    gsub(/\/(.?)/){ "::#{$1.upcase}" }.
  #    gsub(/(?:_+)([a-z])/){ $1.upcase }.
  #    gsub(/(^|\s+)([a-z])/){ $1 + $2.upcase }
  #

end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/string/modulize.rb
facets-3.1.0 lib/core/facets/string/modulize.rb
facets-3.0.0 lib/core/facets/string/modulize.rb
facets-2.9.3 lib/core/facets/string/modulize.rb