Sha256: fd43f3d3f60e237cdd27ffcc609a46a35b11c6c6a72b2b24975fed49d8eb6d79

Contents?: true

Size: 507 Bytes

Versions: 7

Compression:

Stored size: 507 Bytes

Contents

class String

  # The reverse of +camelcase+. Makes an underscored of a camelcase string.
  #
  # Changes '::' to '/' to convert namespaces to paths.
  #
  # Examples
  #   "SnakeCase".underscore           #=> "snake_case"
  #   "Snake-Case".underscore          #=> "snake_case"
  #   "SnakeCase::Errors".underscore   #=> "snake_case/errors"
  #
  def underscore
    gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

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