Sha256: 3973b0df0e84a3ff6164a890d7846b0dee580d503e49cf18fd577046fd03859e

Contents?: true

Size: 350 Bytes

Versions: 2

Compression:

Stored size: 350 Bytes

Contents

require 'term/ansicolor'

class String
  include Term::ANSIColor

  # 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

2 entries across 2 versions & 1 rubygems

Version Path
tailor-1.0.1 lib/ext/string_ext.rb
tailor-1.0.0 lib/ext/string_ext.rb