Sha256: a85304d7a38e9427c14fde6565ead630681d8a823a964c5271deac3235b60351

Contents?: true

Size: 492 Bytes

Versions: 5

Compression:

Stored size: 492 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"
  #
  def modulize
    gsub('__','/').
    gsub(/\/(.?)/){ "::#{$1.upcase}" }.
    gsub(/(?:_+|-+)([a-z])/){ $1.upcase }.
    gsub(/(\A|\s)([a-z])/){ $1 + $2.upcase }
  end

end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
facets-2.5.1 lib/core/facets/string/modulize.rb
facets-2.4.5 lib/core/facets/string/modulize.rb
facets-2.5.0 lib/core/facets/string/modulize.rb
facets-2.5.2 lib/core/facets/string/modulize.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/string/modulize.rb