Sha256: 4c4d8fab8cdd1d4590c84542b46644a98271ea9376460bb95e42bb84a415efd1

Contents?: true

Size: 297 Bytes

Versions: 8

Compression:

Stored size: 297 Bytes

Contents

class String
  # Borrowed from ActiveSupport, this converts camel-case Strings to
  # snake-case.
  #
  # @return [String]
  def underscore
    self.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

8 entries across 8 versions & 1 rubygems

Version Path
tailor-1.2.1 lib/ext/string_ext.rb
tailor-1.2.0 lib/ext/string_ext.rb
tailor-1.1.5 lib/ext/string_ext.rb
tailor-1.1.4 lib/ext/string_ext.rb
tailor-1.1.3 lib/ext/string_ext.rb
tailor-1.1.2 lib/ext/string_ext.rb
tailor-1.1.1 lib/ext/string_ext.rb
tailor-1.1.0 lib/ext/string_ext.rb