Sha256: 4a1e3a609bd7b3625a050b78262af1d96914ef6a45afa4d175af0d288dea77f2

Contents?: true

Size: 510 Bytes

Versions: 7

Compression:

Stored size: 510 Bytes

Contents

class String

  # Translate a (class or module) name to a suitable method name.
  #
  #   My::CoolClass.name.methodize => "my__cool_class"
  #
  #--
  # Rails definition:
  #
  #    gsub(/\//, '__').
  #    gsub(/::/, '__').
  #    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  #    gsub(/([a-z\d])([A-Z])/,'\1_\2').
  #    tr("-", "_").
  #    downcase
  #++
  def methodize
    gsub(/([A-Z]+)([A-Z])/,'\1_\2').
    gsub(/([a-z])([A-Z])/,'\1_\2').
    gsub('/' ,'__').
    gsub('::','__').
    downcase
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

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